1

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?

2
  • Did you mean: path = os.path.abspath(path)?
    – glglgl
    Commented Jun 21, 2013 at 7:06
  • 1
    I find it interesting that you are importing os but not using it to construct your path. a='\\' == os.sep, and path=r"C:"+a+"Windows"+a+"System32" == path=os.path.join("C:","Windows", "System32") Commented Jun 21, 2013 at 7:33

1 Answer 1

3

This should work

import subprocess
subprocess.call(['C:\\Windows\\System32\\PNPUTIL.exe'])
7
  • @AshwiniChaudhary This one should work as well. Just tried it with subprocess.call(['C:\\Windows\\System32\\systeminfo.exe']).
    – glglgl
    Commented Jun 21, 2013 at 7:06
  • @AshwiniChaudhary I'm not a python expert, just do bits of it. I will check and update.
    – Kris
    Commented Jun 21, 2013 at 7:07
  • @Krishnanunni This looks fine, I guess I misread it.(cmd's commands confuse me). +1 anyway Commented Jun 21, 2013 at 7:17
  • 2
    subprocess.call(['C:\Windows\System32\PNPUTIL.exe']) also didn't work,It throws error "Traceback (most recent call last): File "D:\InstallUninstall\new.py", line 8, in <module> subprocess.call(['C:\Windows\System32\PNPUTIL.exe']) File "C:\Python31\lib\subprocess.py", line 428, in call return Popen(*popenargs, **kwargs).wait() File "C:\Python31\lib\subprocess.py", line 658, in init errread, errwrite) File "C:\Python31\lib\subprocess.py", line 868, in _execute_child startupinfo) WindowsError: [Error 2] The system cannot find the file specified" Commented Jun 27, 2013 at 5:48
  • check system32 folder, find the file 'PnPutils.exe'. Try using the case properly as in file name.
    – Kris
    Commented Jun 27, 2013 at 11:32

Not the answer you're looking for? Browse other questions tagged or ask your own question.