简体   繁体   English

如何在python中执行shell命令?

[英]How to execute shell command in python?

Code snippets are as follows: 代码片段如下:

import os
a= "\\"

path=r"C:"+a+"Windows"+a+"System32"

print "\n path :",path

os.chdir('C:')

os.path.abspath(path)

os.chdir(path)

print os.getcwd()

os.system('PNPUTIL.exe')

Result : 结果:

path : C:\Windows\System32

C:\Windows\System32

'PNPUTIL.exe' is not recognized as an internal or external command,
operable program or batch file.

Though the utility is available its not geting identified,wat could be the problem? 虽然实用程序可用,但未确定,可能是问题吗?

This should work 这应该工作

import subprocess
subprocess.call(['C:\\Windows\\System32\\PNPUTIL.exe'])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM