子进程。CREATE_NEW_CONSOLE

Ben*_*Ben 1 python subprocess popen

我有这个Python代码。

import subprocess

subprocess.Popen("airmon-ng check kill", creationflags = subprocess.CREATE_NEW_CONSOLE)
Run Code Online (Sandbox Code Playgroud)

Linux Mint上的Python 2.7.6给我以下错误:

    subprocess.Popen("airmon-ng check kill", creationflags = subprocess.CREATE_NEW_CONSOLE)
    AttributeError: 'module' object has no attribute 'CREATE_NEW_CONSOLE'
Run Code Online (Sandbox Code Playgroud)

Windows 8.1上的相同之处在于:

Traceback (most recent call last):
File "C:\Users\Ben\Dropbox\Coding\jam.py", line 10, in <module>
subprocess.Popen("airmon-ng check kill", creationflags = subprocess.CREATE_NEW_CONSOLE)
File "C:\Python27\lib\subprocess.py", line 710, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 958, in _execute_child
startupinfo)
WindowsError: [Error 2] The system cannot find the file specified
Run Code Online (Sandbox Code Playgroud)

dev*_*ius 5

subprocess.Popen("airmon-ng check kill", shell=True)
Run Code Online (Sandbox Code Playgroud)

会做您想做的,我想是打开一个外壳并airmon-ng check kill通过Python 执行。我仔细阅读了子流程文档,并指出了仅在Windows中可用的CREATE_NEW_CONSOLE状态,creationflags这将解释为什么它在Linux Mint中不起作用。 CREATE_NEW_CONSOLE的文档还指出:

新进程具有一个新的控制台,而不是继承其父级的控制台(默认)。当使用创建Popen时,始终设置此标志shell=True

因此,仅使用shell=True即可完成您想要的事情。