子进程.CREATE_NEW_CONSOLE [英] Subprocess.CREATE_NEW_CONSOLE

查看:393
本文介绍了子进程.CREATE_NEW_CONSOLE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个Python代码.

I have this Python code.

import subprocess

subprocess.Popen("airmon-ng check kill", creationflags = subprocess.CREATE_NEW_CONSOLE)

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

Python 2.7.6 on Linux Mint gives me the following error:

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

在Windows 8.1上也是如此:

The same on Windows 8.1 gives me this:

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

推荐答案

subprocess.Popen("airmon-ng check kill", shell=True)

将做您想做的,我想是打开一个外壳并通过Python执行airmon-ng check kill. 我已经浏览了子流程文档,并且它唯一指向指出creationflags仅在Windows中可用,这将解释为什么它在Linux Mint中不起作用. CREATE_NEW_CONSOLE 的文档也指出

Will do what you want, which I presume is to open a shell and execute airmon-ng check kill through Python. I've looked through the subprocess docs and the only thing pointing to CREATE_NEW_CONSOLE states that creationflags is only available in Windows which would explain why it doesn't work in Linux Mint. The docs for CREATE_NEW_CONSOLE also states that

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

The new process has a new console, instead of inheriting its parent’s console (the default). This flag is always set when Popen is created with shell=True.

因此,仅使用shell=True是执行所需操作的最佳方法.

So just using shell=True is the best way to do what you want.

这篇关于子进程.CREATE_NEW_CONSOLE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆