2

I'm unable to execute the following line:

os.system("timeout 1s bash -c \"ffmpeg -i \""+path+\"+" | <some_<other_cmd>\"")

So the purpose of this command is to set a timeout for the whole command, i.e. pipelining some ffmpeg information from a path.

The problem is because bash -c "CMD" is expected, but the command also contains " ".

Is there another way of defining the \"path\", because the path can contain spaces? Or another solution which can resolve my problem?

Thanks in advance!

gillesC
  • 677
  • 1
  • 5
  • 23

2 Answers2

2

Triple sinqle quotes can do the trick (so that you do not have to escape doublequotes):

os.system('''timeout 1s bash -c "ffmpeg -i "+path+"+" | cat''')

But in general.. Why not use subprocess.call that has saner syntax?

LetMeSOThat4U
  • 6,470
  • 10
  • 53
  • 93
  • The problem occurs because there is a need to put quotes around the path because the path contains spaces, which your solution doesn't resolve. And I'm not familiar with python, I was just changing some old code for my needs. But I'll try to resolve the problem in a different manner so that I won't be needing to group the 2 commands for the timeout. – gillesC Jun 04 '16 at 11:27
0

Has answered similar question in other posts: 1 and 2

you can use subprocess related functions, which all support timeout parameter, to replace os.system

such as subprocess.check_output

ffmpegCmd = "ffmpeg -I %s | %s" % (path, someOtherCmd)
outputBytes = subprocess.check_output(ffmpegCmd, shell=True, timeout=1)
outputStr = outputBytes.decode("utf-8") # change utf-8 to your console encoding if necessary
crifan
  • 12,947
  • 1
  • 71
  • 56