Search code examples
pythonwindowssystemarchive7zip

Cannot run system command


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?


Solution

  • Try:

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

    add => " in (program file section)