当我执行" net start"之类的简单命令时,我正在成功输出输出,如下所示。
Python脚本:
import os
def test():
cmd = ' net start '
output = os.popen(cmd).read()
print output
test()
输出:
C:\Users\test\Desktop\service>python test.py
These Windows services are started:
Application Experience
Application Management
Background Intelligent Transfer Service
Base Filtering Engine
Task Scheduler
TCP/IP NetBIOS Helper
The command completed successfully.
C:\Users\test\Desktop\service>
但是当我执行长命令时(例如:" net start" windows search")我 NOT 获得任何输出。
Python脚本:
import os
def test():
cmd = ' net start "windows search" '
output = os.popen(cmd).read()
print output
test()
输出:
C:\Users\test\Desktop\service>python test.py
C:\Users\test\Desktop\service>
我试过" net start \" windows search \" &#34 ;.也。但同样的问题。
有人可以指导我吗?
答案 0 :(得分:3)
从2.6版开始不推荐使用:此功能已过时。使用
subprocess
模块。请特别检查Replacing Older Functions with the subprocess Module部分。
subprocess.Popen(['net', 'start', 'windows search'], ...)