2017-11-10 14:28:44 +00:00
Cmd
2017-12-24 00:21:09 +00:00
---
2017-11-10 14:28:44 +00:00
2017-12-24 00:21:09 +00:00
.. py:class :: pydu.cmd.TimeoutExpired(cmd, timeout, output=None, stderr=None)
This exception is raised when the timeout expires while waiting for a
child process.
Attributes:
cmd, output, stdout, stderr, timeout
.. py:function :: pydu.cmd.run(ccmd, wait=True, env=None, shell=False, timeout=None, timeinterval=1)
2017-11-10 14:28:44 +00:00
2017-12-14 11:55:37 +00:00
Run cmd based on `` subprocess.Popen `` .
2017-12-23 03:05:22 +00:00
2017-12-14 11:55:37 +00:00
If `` wait `` is True, `` run `` will return the tuple of `` (returncode, stdout) `` .
Note, `` stderr `` is redirected to `` stdout `` . If `` wait `` is False, `` run ``
2017-11-10 14:28:44 +00:00
will return object of `` Popen `` .
2017-12-23 03:05:22 +00:00
2017-11-10 14:28:44 +00:00
`` shell `` is same to parameter of `` Popen `` .
2017-12-23 03:05:22 +00:00
If the process does not terminate after `` timeout `` seconds, a `` TimeoutExpired `` exception will be raised.
`` timeinterval `` is workable when timeout is given on Python 2. It means process status checking interval.
The child process is not killed if the timeout expires, so in order to cleanup properly a well-behaved application should kill the child process and finish communication.
2017-12-14 11:55:37 +00:00
>>> from pydu.cmd import run
>>> run('echo hello')
2017-11-10 14:28:44 +00:00
(0, b'hello\r\n') # Python 3
2017-12-14 11:55:37 +00:00
>>> run('echo hello', wait=False)
2017-11-10 14:28:44 +00:00
<subprocess.Popen at 0x22e4010f9e8>
2017-11-11 12:23:19 +00:00
2017-12-24 00:21:09 +00:00
.. py:function :: pydu.cmd.run(cmd, wait=True, shell=False, env=None, timeout=None, timeinterval=1)
Run cmd with English character sets environment, so that the output will
be in English.
Parameters are same with `` run `` .
.. py:function :: pydu.cmd.terminate(pid)
Terminate process by given `` pid `` .
On Windows, using `kernel32.TerminateProcess` to kill.
On other platforms, using `os.kill` with `signal.SIGTERM` to kill.
2017-11-12 18:25:30 +00:00
.. py:function :: pydu.cmd.cmdline_argv()
2017-11-11 12:23:19 +00:00
Get command line argv of self python process. On Windows when using Python 2,
`` cmdline_argv `` is implemented by using `` shell32.GetCommandLineArgvW `` to get
2017-12-23 03:05:22 +00:00
sys.argv as a list of Unicode strings.
2017-11-11 12:23:19 +00:00
2017-12-24 00:21:09 +00:00
On other platforms or using Python 3, `` cmdline_argv `` is same to `` sys.argv `` .
2017-11-11 12:23:19 +00:00
>>> from pydu.cmd import cmdline_argv
>>> cmdline_argv()
['/Applications/PyCharm.app/Contents/helpers/pydev/pydevconsole.py', '61253', '61254']