How to just call a command and not get its output [duplicate]

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 … Read more

Python subprocess and user interaction

Check out the subprocess manual. You have options with subprocess to be able to redirect the stdin, stdout, and stderr of the process you’re calling to your own. from subprocess import Popen, PIPE, STDOUT p = Popen([‘grep’, ‘f’], stdout=PIPE, stdin=PIPE, stderr=STDOUT) grep_stdout = p.communicate(input=”one\ntwo\nthree\nfour\nfive\nsix\n”)[0] print grep_stdout You can also interact with a process line by … Read more

Getting an error – AttributeError: ‘module’ object has no attribute ‘run’ while running subprocess.run([“ls”, “-l”])

The subprocess.run() function only exists in Python 3.5 and newer. It is easy enough to backport however: def run(*popenargs, **kwargs): input = kwargs.pop(“input”, None) check = kwargs.pop(“handle”, False) if input is not None: if ‘stdin’ in kwargs: raise ValueError(‘stdin and input arguments may not both be used.’) kwargs[‘stdin’] = subprocess.PIPE process = subprocess.Popen(*popenargs, **kwargs) try: … Read more

How to get output from subprocess.Popen(). proc.stdout.readline() blocks, no data prints out

You obviously can use subprocess.communicate but I think you are looking for real time input and output. readline was blocked because the process is probably waiting on your input. You can read character by character to overcome this like the following: import subprocess import sys process = subprocess.Popen( cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE ) while True: out … Read more