11

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.

cyram
  • 820
  • 8
  • 22
  • in addition to escaping backslashes in the string, you should drop unnecessary quotes `'"'` around `pathToFile` and drop unnecessary argument `shell=True` in the `Popen` call. – jfs Oct 14 '13 at 08:38

1 Answers1

4

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"
Paul Evans
  • 27,315
  • 3
  • 37
  • 54
  • That helped! Now it says "ffprobe.exe is not recognized as an internal or external command, operable program or batch file." I have put ffprobe: in the same directory, put the full path (with an r in front) to ffprobe: (e.g. C:\somefolder\ffprobe), put a relative path in front of the name ".\ffprobe.exe", put a copy of ffprobe.exe in C:\Windows\System32, and made sure that directory was in PATH, and added an 'r' in front of 'ffprobe.exe' for good measure. It still doesn't recognize it. At least I moved to the next error though. Thanks for the help! – cyram Oct 11 '13 at 12:13
  • 1
    @cyram are you running into issues with spaces in the folder names? – Marcel Wilson Oct 11 '13 at 15:22