How do I eliminate Windows consoles from spawned processes in Python (2.7)? [duplicate]

You need to set the startupinfo parameter when calling Popen. Here’s an example from an Activestate.com Recipe: import subprocess def launchWithoutConsole(command, args): “””Launches ‘command’ windowless and waits until finished””” startupinfo = subprocess.STARTUPINFO() startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW return subprocess.Popen([command] + args, startupinfo=startupinfo).wait() if __name__ == “__main__”: # test with “pythonw.exe” launchWithoutConsole(“d:\\bin\\gzip.exe”, [“-d”, “myfile.gz”])

What’s the difference between subprocess Popen and call (how can I use them)?

There are two ways to do the redirect. Both apply to either subprocess.Popen or subprocess.call. Set the keyword argument shell = True or executable = /path/to/the/shell and specify the command just as you have it there. Since you’re just redirecting the output to a file, set the keyword argument stdout = an_open_writeable_file_object where the object … Read more

c popen won’t catch stderr

popen gives you a file handle on a process’ stdout, not its stderr. Its first argument is interpreted as a shell command, so you can do redirections in it: FILE *p = popen(“prog 2>&1”, “r”); or, if you don’t want the stdout at all, FILE *p = popen(“prog 2>&1 >/dev/null”, “r”); (Any other file besides … Read more

How to run a background process and do *not* wait?

Here is verified example for Python REPL: >>> import subprocess >>> import sys >>> p = subprocess.Popen([sys.executable, ‘-c’, ‘import time; time.sleep(100)’], stdout=subprocess.PIPE, stderr=subprocess.STDOUT); print(‘finished’) finished How to verify that via another terminal window: $ ps aux | grep python Output: user 32820 0.0 0.0 2447684 3972 s003 S+ 10:11PM 0:00.01 /Users/user/venv/bin/python -c import time; time.sleep(100)

popen() alternative

Why aren’t you using pipe/fork/exec method? pid_t pid = 0; int pipefd[2]; FILE* output; char line[256]; int status; pipe(pipefd); //create a pipe pid = fork(); //span a child process if (pid == 0) { // Child. Let’s redirect its standard output to our pipe and replace process with tail close(pipefd[0]); dup2(pipefd[1], STDOUT_FILENO); dup2(pipefd[1], STDERR_FILENO); execl(“/usr/bin/tail”, … Read more