I'm trying to convert a long, complex, Windows batch file into Python.
Things work except for subtle problems, which I suspect have something to do with quoting, but can't quite figure out.
In a batch file, this works fine:
Reg.exe add "HKCR\7-Zip.zip\shell\open\command" /ve /t REG_SZ /d "\"C:\Program Files\7-Zip\7zFM.exe\" \"%%1\"" /f
This Python code is meant to, but doesn't, do the same thing:
import os, subprocess
cmd = r'Reg.exe add "HKCR\7-Zip.zip\shell\open\command" /ve /t REG_SZ /d "\"C:\Program Files\7-Zip\7zFM.exe\" \"%%1\"" /f'
#os.system(cmd)
subprocess.call(cmd, shell=True)
Note that the (raw) string cmd
and the batch file are exactly identical.
Both the os.system() and subprocess.call() result in the same thing - no error (Reg.exe says everything is fine), but a different effect on the system.
In my testing, the batch file configures the archiver 7z to open the .ZIP file itself (correct result).
The Python code causes 7z to open the folder where the .ZIP is located (wrong).
How to get Python to do what the batch file does?