简体   繁体   中英

Python: Calling executable fails

I'm trying to run any one of these in Python...

subprocess.call(r"C:\Windows\System32\fsquirt.exe", shell=True)
subprocess.call("C:\\Windows\\System32\\fsquirt.exe", shell=True)
subprocess.call(r"C:/Windows/System32/fsquirt.exe", shell=True)
subprocess.call("C:/Windows/System32/fsquirt.exe", shell=True)

They all result in...

'C:/Windows/System32/fsquirt.exe' is not recognized as an internal or external command,
operable program or batch file.

If I just copy fsquirt.exe into the local directory I can call it from there, so I'm sure I must just be doing something noob-ish with how I'm using directories.

How should I do this?

The problem was that I'm using 64 bit Windows which doesn't use System32 (running from 32bit Python). 64 bit Windows typically uses SysWOW64 instead of System32. Calling the virtual directory Sysnative instead of either of those will sort out which one needs to be called based on what you're running (for me, 32bit Python). Fsquirt exists only in System32, not SysWOW64. This is different to something like Notepad which exists in both.

subprocess.call("C:/Windows/Sysnative/fsquirt.exe")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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