0

I made some c# program and I tried to use c# program on Python. C# program is CLI and use by CMD. On CMD prompt I can use my program like below command test.exe "C:\Users\Downloads\test file\1.txt" "C:\Users\Downloads\test file\2.txt"

But when I tried on python code.

    AUDIO_TOOL = r"C:/Users/Downloads/test.exe"
    filepath = r"C:/Users/Downloads/test file/1.txt"
    binary_file_path = r"C:/Users/Downloads/test file/2.txt"
    subprocess.call(["%s" % AUDIO_TOOL, r"%s" % filepath, r"%s" % binary_file_path], shell=True)

path that without space work properly but path with space does not work at all. please help me.

ironykim
  • 3
  • 3
  • Try with `shell=False` or call it like this: `subprocess.call('%s "%s" "%s"' % (AUDIO_TOOL, filepath, binary_file_path), shell=True)` (string instead of list). There's likely some problem with the shell splitting the arg by space into multiple args if the arg is not wrapped in quotation marks. You could confirm that by printing `args` at the top of in the C# program. By the way: `"%s" % filepath` resolves to just `filepath`, i.e. there's no need for %-formatting. And raw strings (`r"..."`) are only needed when you have backslashes (\\) in them and don't want to have to escape them (\\\). – Czaporka Nov 18 '20 at 18:56

1 Answers1

0

You have to enclose the whole command in quotation marks

this How do I use spaces in the Command Prompt? may be help you

Mohsen Koorani
  • 241
  • 2
  • 10