0

I am currently trying to run a specific command in a windows terminal, but from a Python (3.7.7) script. I know that this command works in CMD terminal:

"F:\Prog Folder\7-Zip\7z" e "F:\Folder Name\Zipfile.7z" -o"F:\Folder Name\Dolphin Folder" *.iso -mx5

However, due to syntax and sensitivity of Windows, it isn't that simple to call the subprocess and use the same command. Here is what I have now as part of my python script:

import subprocess

subprocess.run(['cmd', '/k', "\"\"F:\Prog Folder\7-Zip\7z\" \"x\" \"F:\Folder Name\Zipfile.7z\" \"-o\"F:\Folder Name\Dolphin Folder\"\" \"*.iso\" \"-mx5\"\""])

I have also tried (subprocess.call) and am still getting this error from cmd terminal and cannot figure out the problem:

The filename, directory name, or volume label syntax is incorrect.

Any recommendations or advice for this? I know the backslashes are sensitive, but I thought I had it correct...

EDIT:

I have tried the suggestions in the comments:

os.system(""F:\Prog Folder\7-Zip\7z" e "F:\Folder Name\Zipfile.7z" -o"F:/Folder Name/Dolphin Folder" *.iso -mx5")

This gave me an "invalid syntax" error and highlighted the drive letter "F"

I have tried subprocess.call and subprocess.run as indicated on Calling an external command from Python with no luck. I just need to basically execute the same line of code that works in CMD but through python; so it must be that syntax is the issue, but no pre-existing question on StackOverflow works with my situation...

NatAnal
  • 1
  • 1
  • try `import os` then `os.system(""F:\Prog Folder\7-Zip\7z" e "F:\Folder Name\Zipfile.7z" -o"F:\Folder Name\Dolphin Folder" *.iso -mx5")` Using this, you can paste your CMD line directly without needing all the parameters. – mime Apr 30 '20 at 03:35
  • 1
    Duplicate of [Calling an external command from Python](https://stackoverflow.com/questions/89228/calling-an-external-command-from-python)? – mime Apr 30 '20 at 03:37
  • Does this answer your question? [Calling an external command from Python](https://stackoverflow.com/questions/89228/calling-an-external-command-from-python) – Guy Goldenberg Apr 30 '20 at 12:05
  • Tried the command from fez.tival and checked the "Duplicate" question but it hasn't solved this – NatAnal May 01 '20 at 01:53

0 Answers0