Home > Software design >  Cannot run system command
Cannot run system command

Time:01-29

I am trying to zip a folder using python. The following command works from command prompt:

7z a C:\\Temp\\ C:\\Temp\\

But the following only show an error code of 1:

os.system("7z a C:\\Temp\\ C:\\Temp\\")

subprocess.call(["7z a C:\\Temp\\ C:\\Temp\\"], shell=True)

os.system("C:\Program Files\7-Zip\7z.exe a C:\\Temp\\ C:\\Temp\\")

Calling exe's with full path to them works for me well with the above approaches. Could anyone suggest a solution?

CodePudding user response:

Try:

os.system("C:\\"Program Files\"\7-Zip\7z.exe a C:\\Temp\\ C:\\Temp\\")

add => " in (program file section)

  •  Tags:  
  • Related