Python内置的subprocess.Popen对象

具体内容参见:https://docs.python.org/3/library/subprocess.html

大概来说,就是可以对应输入的命令产生一个进程,该进程实例内置如下方法。

 |  communicate(self, input=None, timeout=None)
 |      Interact with process: Send data to stdin.  Read data from
 |      stdout and stderr, until end-of-file is reached.  Wait for
 |      process to terminate.  The optional input argument should be
 |      bytes to be sent to the child process, or None, if no data
 |      should be sent to the child.
 |      
 |      communicate() returns a tuple (stdout, stderr).
 |  
 |  kill = terminate(self)
 |  
 |  poll(self)
 |  
 |  send_signal(self, sig)
 |      Send a signal to the process.
 |  
 |  terminate(self)
 |      Terminates the process.
 |  
 |  wait(self, timeout=None, endtime=None)
 |      Wait for child process to terminate.  Returns returncode
 |      attribute.

在windows系统中,kill是terminate方法的别名,在linux系统中,kill向进程发送SIGKILL信号,terminate方法向进程发送SIGTERM信号。

猜你喜欢

转载自www.cnblogs.com/lyg-blog/p/8966978.html