Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python subprocess arguments

For example I am using ffplay and want to run this command -bufsize[:stream_specifier] integer (output,audio,video)

At the moment I have this:

subprocess.call(["ffplay", "-vn", "-nodisp","-bufsize 4096", "%s" % url])

But this says it is invalid.

like image 273
user673906 Avatar asked Jul 27 '12 00:07

user673906


People also ask

How do you pass arguments in subprocess Popen?

To pass variables to Python subprocess. Popen, we cann Popen with a list that has the variables we want to include. to call Popen with the command list that has some static and dynamic command arguments.

What is Popen in Python?

Python method popen() opens a pipe to or from command. The return value is an open file object connected to the pipe, which can be read or written depending on whether mode is 'r' (default) or 'w'.

What is subprocess Check_output in Python?

The subprocess. check_output() is used to get the output of the calling program in python. It has 5 arguments; args, stdin, stderr, shell, universal_newlines. The args argument holds the commands that are to be passed as a string.

How can we avoid shell true in subprocess?

From the docs: args is required for all calls and should be a string, or a sequence of program arguments. Providing a sequence of arguments is generally preferred, as it allows the module to take care of any required escaping and quoting of arguments (e.g. to permit spaces in file names).


1 Answers

As JBernardo mentioned in a comment, separate the "-bufsize 4096" argument into two, "-bufsize", "4096". Each argument needs to be separated when subprocess.call is used with shell=False (the default). You can also specify shell=True and give the whole command as a single string, but this is not recommended due to potential security vulnerabilities.

You should not need to use string formatting where you have "%s" % url. If url is a string, pass it directly, otherwise call str(url) to get a string representation.

like image 85
Abe Karplus Avatar answered Sep 23 '22 02:09

Abe Karplus