Cmd 命令

pydu.cmd.run(cmd, wait=True, shell=True)

基于 subprocess.Popen 执行命令。如果 wait 是 True,execute 将会返回 (returncode, stdout) 元组。注意, stderr 被重定向到了 stdout。如果 wait 是 False, execute 将会返回 Popen 对象。shellPopen 中的参数一样。"

>>> from pydu.cmd import run
>>> run('echo hello')
(0, b'hello\r\n')  # Python 3
>>> run('echo hello', wait=False)
<subprocess.Popen at 0x22e4010f9e8>
pydu.cmd.cmdline_argv()

获取当前Python进程的命令行参数。在Windows上使用Python 2时, cmdline_argv 的实现是基于 shell32.GetCommandLineArgvW 获取列表元素为Unicode字符串形式的sys.argv。而在其他平台或者是使用Python 3时, cmdline_argvsys.argv 相同。

以下是在PyCharm的Python控制台中的例子:

>>> from pydu.cmd import cmdline_argv
>>> cmdline_argv()
['/Applications/PyCharm.app/Contents/helpers/pydev/pydevconsole.py', '61253', '61254']