user2507907
user2507907

Reputation: 11

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?

Upvotes: 1

Views: 588

Answers (1)

Kris
Kris

Reputation: 8873

This should work

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

Upvotes: 3

Related Questions