Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Popen Cannot Find the File Specified

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 the error:

[Error 2] The system cannot find the file specified

What I have tried:

  • Changing shell=True to shell=False
  • Combining the command into a single string instead of using a list (I even print it to screen, and I can copy and paste into a command prompt where the file runs and gives the expected output (no error)
  • I made sure that ffprobe.exe is located in the PATH and can be executed from the command line without specifying a directory

Things of note:

  • The file is located on a mapped network drive (R)
  • The file has spaces in the filename, this is why I surrounded it by quotes.

I'm sure I'm missing something simple. Can anyone point me in the right direction? I've done quite a lot of searching on this site and others and trying suggestions.

like image 500
cyram Avatar asked Oct 11 '13 11:10

cyram


1 Answers

The \ symbol counts as an escape character in python, use r to turn that off:

pathToFile = r"R:\T2 Output\12345--01--Some File 1--ABCD.mp4"
like image 51
Paul Evans Avatar answered Sep 22 '22 00:09

Paul Evans