Questions tagged [subprocess]

The Python subprocess module allows you to spawn new processes, connect to their input/output/error pipes, and obtain their return codes. Use it to run a shell command or an executable in Python.

The Python subprocess module allows you to spawn new processes, connect to their input/output/error pipes, and obtain their return codes.

If you want to run Python code in a separate process consider instead.

is preferable to subprocess in some cases.

Waiting for a command to finish and getting the result

Interacting with a subprocess while it is still running

Windows

Misc

12158 questions
3
votes
1 answer

Logging during a Subprocess Python

So I have created a logger which logs to both file and console. However, I need to call subprocess to run other python files but the problem is that console and file is only populated with logging messages once the subprocess has complete even…
Bryce Ramgovind
  • 3,127
  • 10
  • 41
  • 72
3
votes
1 answer

How to fix hanging in subprocess.check_output()

I am trying to execute the following code to run a python script with a configure file as input: try: process = check_output(["python", "E:/SpaceWeather/Source_codes/codes_written/tec-suite-master/tecs.py", \ …
R Thompson
  • 353
  • 3
  • 15
3
votes
1 answer

Python: handling interrupts whilst running subprocess

I wrote a simple Python parser for tcpdump. The idea is to continuously run tcpdump as a subprocess, parse its output and output basic reports when the user requests them (by Ctrl-Z interrupts) without stopping the script. A Ctrl-C should also…
ktorn
  • 1,032
  • 8
  • 14
3
votes
1 answer

Why does this open software code run the same command line argument twice?

I am building an online judge that takes a user's c++ code, and tells them whether or not the output from it is correct. Currently, I'm looking at an open source python project to see how to do it. In the example code, they run both…
Evan Wild
  • 67
  • 5
3
votes
2 answers

Can't read stderr from subprocess.Popen

I want to start a child process and read its stderr, but so far, I can't read anything at all using subprocess.Popen, even stdout. I'm trying to use subprocess.communicate() to read from stdout and stderr. This is what I do: import subprocess p =…
sashoalm
  • 75,001
  • 122
  • 434
  • 781
3
votes
1 answer

How to handle interactive apt-get installation with python 3.6 subprocess.Popen() function?

Issue: I wrote the following python 3.6 script using the subprocess.Popen() function to run the linux apt-get command to install debian packages. I encountered a package, ubuntu-restricted-extras, that required user interaction during the…
Sun Bear
  • 7,594
  • 11
  • 56
  • 102
3
votes
0 answers

Can I use Select-Object in subprocess.run

I am attempting convert a PowerShell command that generates a list of applications that are currently installed on a device in Python to use that list in an application uninstaller. The command I am working with is: Get-ItemProperty…
Monpolyme1
  • 33
  • 4
3
votes
1 answer

java: closing subprocess std streams?

from the javadoc for java.lang.Process: The methods that create processes may not work well for special processes on certain native platforms, such as native windowing processes, daemon processes, Win16/DOS processes on Microsoft Windows, or shell…
Jason S
  • 184,598
  • 164
  • 608
  • 970
3
votes
1 answer

How do I run a PowerShell script with parameters from Python

I'm trying to run PowerShell scripts that have parameters from Python 3.7.3, but don't know how to properly call the function in Popen What I'm trying to do with my PowerShell script is login to Cisco routers and run Cisco IOS commands on x number…
Jgreene44
  • 47
  • 1
  • 2
  • 7
3
votes
1 answer

Import runtime installed module using pip in python 3

I want to install and import Python 3 modules at runtime. I'm using the following function to install modules at runtime using pip: def installModules(modules): for module in modules: print("Installing module {}...".format(module)) …
Jacob Krieg
  • 2,834
  • 15
  • 68
  • 140
3
votes
0 answers

Subprocess pipe broken only when running a script

I'm trying to test a small server application using python. The application is working a bit like a remote shell - it takes an input and outputs some data based on the input. My initial try looks like this: #!/usr/bin/python3 import subprocess nc =…
ja2142
  • 892
  • 15
  • 23
3
votes
2 answers

how to json parse a python output and store its values like in dict or variables?

I have a python code that outputs json import json from faker import Faker import random from random import randint import subprocess fake = Faker('en_US') for _ in range(1): sms = { "name": fake.name(), "email": fake.email(), …
user11124889
3
votes
3 answers

How can I catch errors from subprocess in a python cgi script?

I'm trying to write a Python CGI script that will call sox (an audio processing program) using subprocess. The problem is that when I get errors from the sox call, everything crashes and I get a "malformed header" error from Apache. The relevant…
Valkyrie Savage
  • 575
  • 2
  • 6
  • 21
3
votes
1 answer

subprocess within subprocess. How to propagate the output on error?

I use subprocess to run a script. But that called script itself uses subprocess to execute some commands. The problem is that when I catch the exception in the outer script, it just says that there was an error in the called script. So, my question…
MetallicPriest
  • 29,191
  • 52
  • 200
  • 356
3
votes
0 answers

How to capture stdout / stderr when using multiprocessing.Process

I'm trying to emulate the subprocess.Popen stdout / stderr for Python methods targets, meaning, I want to create N parallel jobs, with unique stdout / stderr handlers. This is my current code: #!/bin/python import time import multiprocessing as…
CIsForCookies
  • 12,097
  • 11
  • 59
  • 124
1 2 3
99
100