Python popen cannot find the specified file

I have the following code

pathToFile = "R:\T2 Output\12345--01--Some File 1--ABCD.mp4" process = subprocess.Popen(['ffprobe.exe', '-show_streams', '"'+pathToFile+'"'], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) 

I get an error message:

 [Error 2] The system cannot find the file specified 

What I tried:

  • Shell change = True for shell = False
  • Combining a command in one line instead of using a list (I even print it on the screen, and I can copy and paste into the command line where the file is running and gives the expected output (without errors)
  • I made sure that ffprobe.exe is in PATH and can be executed from the command line without specifying a directory

Notes:

  • The file is located on a mapped network drive (R)
  • There are spaces in the file name of the file, so I surrounded it with quotation marks.

I am sure that I am missing something simple. Can someone point me in the right direction? I have done quite a few searches on this site and others and have tried the suggestions.

+6
source share
1 answer

The \ character is considered as an escape character in python, use r to disable it:

 pathToFile = r"R:\T2 Output\12345--01--Some File 1--ABCD.mp4" 
+3
source

Source: https://habr.com/ru/post/955763/


All Articles