0

I am trying to use python for ffprobe. but i am getting error.

i wish to create a file which will have all the data

videofile=raw_input('What is the file path?')
cmd = ['ffprobe', '-i', 'videofile', '>' 'file.txt']
response = subprocess.check_output(cmd,shell=True,stderr=subprocess.STDOUT)

but i am getting error

raise CalledProcessError(retcode, cmd, output=output)subprocess.CalledProcessError: Command '['ffprobe', '-i', 'videofile', '>file.txt']' returned non-zero exit status 1
MD. Khairul Basar
  • 4,976
  • 14
  • 41
  • 59
user583088
  • 989
  • 1
  • 6
  • 10
  • 2
    videofile is a variable. You are quoting it as a string. See [here](http://stackoverflow.com/questions/4795190/pass-variable-to-subprocess-call-in-python). – skytaker May 23 '16 at 20:01
  • i tried to do this str_args = [ str(x) for x in cmd ]response = subprocess.check_output(str_args, shell=True, stderr=subprocess.STDOUT) but still the same error – user583088 May 23 '16 at 20:58
  • 1
    When using `shell=True`, you should pass a command-line string instead of a list. For example: `cmd = 'ffprobe -i "%s" > file.txt' % videofile`. Windows always uses a command-line string. Under the hood, `subprocess.list2cmdline` converts a list to a string using the MSVC parsing rules, but cmd.exe doesn't follow these rules. You also need to use a string on POSIX systems, which ensures the arguments are passed to the command rather than the shell. – Eryk Sun May 23 '16 at 21:18
  • if you don't understand the difference between `videofile` and `'videofile'` in Python then you should [step back and learn the basics](https://wiki.python.org/moin/BeginnersGuide/NonProgrammers) otherwise you'll spend all the time fixing trivial preventable errors. – jfs May 24 '16 at 10:42

0 Answers0