1

I'm trying to open a file with spaces in path with subprocess.call function but I can't get it working.

import subprocess
subprocess.call(['cmd','/c','start C:/Users/akg/Desktop/file 1.png'])

I've tried also

import subprocess
file= '"C:/Users/akg/Desktop/file 1.png"'
subprocess.call(['cmd','/c','start '+file])

But I still getting this error
1st case : 1st case screenshot, 2nd case 2nd case : screenshot even spliting the command whenever there is a whitespace is not working

Community
  • 1
  • 1
ayar anasse
  • 172
  • 6
  • 2
    Possible duplicate of [Handling directories with spaces Python subprocess.call()](https://stackoverflow.com/questions/11846232/handling-directories-with-spaces-python-subprocess-call) – Peter Wood Oct 04 '18 at 11:18
  • It's a little bit different. it didn't solve my problem – ayar anasse Oct 04 '18 at 11:35

2 Answers2

1

You should put every argument as a separate item in the list passed to subprocess.call:

subprocess.call(['cmd','/c','start', 'C:/Users/akg/Desktop/file 1.png'])
blhsing
  • 91,368
  • 6
  • 71
  • 106
0

The solution that worked for me is to delete the start option as described here : Opening file with spaces in Windows via Command Prompt

import subprocess
subprocess.call(['cmd','/c',"C:/Users/akg/Desktop/file 1.png"])

or

subprocess.call(['cmd', '/c', 'start', "", "C:/Users/akg/Desktop/file 1.png"])

Thank you all

ayar anasse
  • 172
  • 6