Passing double quote shell commands in python to subprocess.Popen()?

前端 未结 5 407
自闭症患者
自闭症患者 2020-11-29 05:34

I\'ve been trying to pass a command that works only with literal double quotes in the commandline around the "concat:file1|file2" argument for ffmpeg.

5条回答
  •  無奈伤痛
    2020-11-29 06:12

    I have been working with a similar issue, with running a relatively complex command over ssh. It also had multiple double quotes and single quotes. Because I was piping the command through python, ssh, powershell etc.

    If you can instead just convert the command into a shell script, and run the shell script through subprocess.call/Popen/run, these issues will go away.

    So depending on whether you are on windows or on linux or mac, put the following in a shell script either (script.sh or script.bat)

    ffmpeg -i "concat:1.ts|2.ts" -vcodec copy -acodec copy temp.mp4
    

    Then you can run

    import subprocess; subprocess.call(`./script.sh`; shell=True)
    

    Without having to worry about single quotes, etc.

提交回复
热议问题