Alex Rivera | Logout

How to just call a command and not get its output

Asked 2011-02-14T20:22:07.887
40

In Python, what is the shortest and the standard way of calling a command through subprocess but not bothering with its output.

I tried subprocess.call however it seems to return the output. I am not bothered with that, I just need to run the program silently without the output cluttering up the screen.

If it helps, I am callling pdflatex and my intention is just to call it.

Edit
Report

1 Answer

62

In case your process produces significant amounts of output that you don't want to buffer in memory, you should redirect the output to the electronic trash can:

subprocess.run(["pdflatex", filename], stdout=subprocess.DEVNULL)

The special value DEVNULL indicates that the output is sent to the appropriate null device of your operating system (/dev/null on most OSes, nul on the other one).

answered 2012-09-19T21:34:57.107

Your Answer