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
3 answers

How to use for loop in Subprocess.run command

I'm using subprocess.run to run a command that has a for loop in it but not getting back the expected result. Here's a simplified case that shows the issue. In bash shell: for i in {1..3}; do echo ${i}; done The result is: 1 2 3 Which is what I…
Justin Owusu
  • 31
  • 1
  • 2
3
votes
1 answer

Why does Python ignore source files in favor of pyc files sometimes?

I've got a situation where I rapidly change Python source files on disk and, for each change, run them with Python in a subprocess (it's for a mutation testing tool). I have found that in some cases, the Python subprocess either doesn't see the…
abingham
  • 1,294
  • 1
  • 10
  • 17
3
votes
1 answer

In subprocess.Popen, which file does bufsize apply to?

I'm in need of setting the stderr stream in a Popen call to line-buffered. I discovered the bufsize argument, but it doesn't say which of the 3 (stdin, stdout, stderr) files it's actually applied to. Which file does the bufsize argument modify? How…
Matt Joiner
  • 112,946
  • 110
  • 377
  • 526
3
votes
1 answer

Execute echo command within a Python script

I am trying to execute an echo command within a python script. If I do it in the terminal, it looks like this: echo -n -e '{"DATE": "Wednesday, May 04, 2016", "message": "ADIsss ", "INDEX_CLOSING_VALUE": "4428.61"}'"\0" | nc -w0 127.0.0.1…
Pradeep Chandran
  • 327
  • 5
  • 11
3
votes
1 answer

Stdout to dev/null not working with subprocess module in python3.6

Using Python 3.6.7 on Ubuntu 18.04.2 LTS I am trying to invoke a shell script through python script, and expect the stdout to be null i.e. I do not want console output. Snippet of the program def command_execution(self, cmd, cwd=None): """…
malhar
  • 562
  • 1
  • 9
  • 21
3
votes
3 answers

Check if a socket is busy or not

I am new to Socket Programming in Python. I have written the following code in Python 3.7: trialSocketList.py import subprocess import sys HOST = sys.argv[1] PORT = sys.argv[2] command = "tnc " + HOST + " -PORT…
Code_Ninja
  • 1,729
  • 1
  • 14
  • 38
3
votes
1 answer

Subprocess in Spyder, matplotlib and prints do not work

Running this on a regular console works well, but from Spyder the window does not show up. Prints neither btw. main.py: import subprocess subprocess.Popen("test.py", shell=True) test.py: import matplotlib.pyplot as…
Rémi Baudoux
  • 542
  • 3
  • 16
3
votes
1 answer

Output data from subprocess command line by line

I am trying to read a large data file (= millions of rows, in a very specific format) using a pre-built (in C) routine. I want to then yeild the results of this, line by line, via a generator function. I can read the file OK, but where as just…
michjnich
  • 2,796
  • 3
  • 15
  • 31
3
votes
0 answers

Does subprocess inherit python's linux capabilities?

I'm using a program to issue a tc command via the subprocess module, but tc is outputting RTNETLINK answers: Operation not permitted To solve this, I have given python the CAP_NET_ADMIN capability with the epi flags, but I still am not able to issue…
spkvn
  • 184
  • 3
  • 17
3
votes
3 answers

Ctrl C won't kill looped subprocess in Python

Is there a proper way to create a script that loops through files in a folder and executes a subprocess that can be externally killed with Ctrl C? I have something like the following embedded in a pipeline and cannot Ctrl C it from the command line…
ENZSIO
  • 183
  • 3
  • 11
3
votes
2 answers

FileNotFoundError: [Errno 2] No such file or directory: 'bash' when running gunicorn server from .service file

Getting FileNotFoundError: [Errno 2] No such file or directory: 'bash' error while running my gunicorn python app form .service file. However running gunicorn command by itself(not from .service file) works fine. gunicorn command to run the…
smriti
  • 1,073
  • 1
  • 13
  • 25
3
votes
2 answers

Python: Opening a unicode named xls file from the script

How do you open a unicode named file (with spaces) from within a Python script under Windows? filename for example: Hello עולם.xls For a non-unicode non-spaced xls file, os.system(filename) works well. For a non-unicode spaced xls file,…
Jonathan Livni
  • 101,334
  • 104
  • 266
  • 359
3
votes
2 answers

Subprocess check_output cutting my output short

I have to write the time it takes for several C programs to run on several files using: time ./program filename to a spread sheet and am using subprocess.check_output to get the stdout as a string. I should get something along the lines of: real …
DMatza
  • 63
  • 4
3
votes
2 answers

Python & Subprocess - Monitor process without locking up

I have the idea of creating a control panel to monitor multiple scripts and processes. Having built the interface in advance, I seem to struggle with detecting the status of subprocess commands, getting a locked-up control panel as the child process…
eymas
  • 105
  • 2
  • 15
3
votes
1 answer

How do time tracking softwares find screen time of applications?

I wanted to write a time tracking software using python for windows. How do I approach finding the total screen time of individual applications? Is there any windows service which tracks the total on screen time spent by a particular application…
Tarun Khare
  • 1,447
  • 6
  • 25
  • 43
1 2 3
99
100