rahuL
rahuL

Reputation: 3420

Suppress verbose output of shell command in python

I am running a shell command in a python script which installs ruby and rubygems using the subprocess function:

subprocess.call("yum install ruby rubygems -y  2>&1", shell=True)

In this however, the 2>&1 doesn't seem to suppress the output like in a normal bash script. Is there any other way to suppress the output?

Upvotes: 1

Views: 897

Answers (2)

akozin
akozin

Reputation: 529

You forgot this:

1>/dev/null

So, the result script will be:

subprocess.call("yum install ruby rubygems -y  2>&1 1>/dev/null", shell=True)

Upvotes: 2

Steve Barnes
Steve Barnes

Reputation: 28390

If you really need to do this then - Use subprocess.Popen with stdout and stderr redirected to pipes.

Upvotes: 1

Related Questions