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.
subprocess
12,338
questions
0
votes
0
answers
32
views
Python subprocess.Popen.communicate() does not wait for the process to complete
On Ubuntu 22, using Python 3.10, I need to set up a VPN connection and analyze the response from the VPN server. I do this as follows:
connect_command = ['ip', 'netns', 'exec', 'vpn_test_namespace', '...
0
votes
1
answer
36
views
"Operation not permitted" when trying to compile code in Databricks
I am trying to compile my code in Databricks using the following code:
import subprocess
process = subprocess.Popen(["python", "setup.py", "bdist_wheel"],
...
1
vote
1
answer
38
views
How can I redirect stdout and stderr of subprocess in python to same file without losing the order
I have a simple script to mimic a program writing to stdout and stderr streams interleaved.
import sys
import time
for i in range(5):
print(int(time.time()), "This is Stdout")
print(...
1
vote
0
answers
36
views
Variables set inside the rcfile are NOT accessible through Python
I've a shell script and a python script organized as follows (CAN NOT change the directory structure):
~
├── a.py
├── b
└── c.sh
The MWEs are as follows:
c.sh
#!/bin/sh
rcfile=$(mktemp)
export ...
0
votes
0
answers
23
views
Subprocesses from within an Inkscape extension
I have a couple instances in which I cannot seem to be able to run subprocesses from within an Inkscape extension. One is this case:
def close_dialog(self, name=None):
try:
...
0
votes
0
answers
13
views
python subprocess modify incoming stream and printing it live
Note: This seems like a solved problem, but I couldn't find a solution.
I have some command line utility I need to use. For example something like
import sys, time
for i in range(3):
print('...
1
vote
0
answers
39
views
Pass Subprocess Output to GUI Live
I have a python program that wraps another program I'm running with subprocess.run(). The program has a great console output that I'd like to show in the GUI:
I'm struggling to figure out how to ...
1
vote
0
answers
24
views
Runing a script written for python2.7 using subprocess.run in a script written in python3.11
In my company there is a script: install.py that is written in python2.7.
The issue
I'm writing a script to run this script from my own python script which I've written in python3.11.
In the beginning ...
0
votes
0
answers
24
views
Custom GUI app for hotspotshield issue on Linux
I'm trying to build a custom GUI app on Python for hotspotshield VPN, a bit like this one, but more fitted for my needs: https://github.com/kiraitachi/PyShieldGUI
I am having an issue with sending ...
1
vote
0
answers
21
views
Running a script in a virtualized environment, capturing output and abstacting keyboard and mouse inputs from main system
I have an autonomous software development system, which is able to generate and iteratively develop an application.
The agent has the ability to run terminal commands like any other developer. for ...
0
votes
0
answers
24
views
Using subprocess.check_call with pip install —trusted-host [duplicate]
In Python (vsCode): I have my code working but to make it share-able and do not want an executable. The problem is that in order to install pptx, we need to use the --trusted-download ***** in the pip ...
0
votes
2
answers
44
views
How to create a docker container, in a python script, which runs a python script in the container?
I'm creating a website similar to leetcode where users can submit code. I'll be running this code in a docker container for security measures. My code isn't behaving how I was expecting it to. I've ...
0
votes
0
answers
30
views
Cannot compare the output of subprocess.check_output() not comparing with a string?
I have this below code in python:
p4status = subprocess.check_output(['p4', 'status', f'{str(getP4Root())}/{self.dev_pattern}/...'],
cwd=getP4Root(), env=self.env)....
0
votes
1
answer
30
views
Issue with ANSI Escape Codes in Output When Running Shell Script via Python Subprocess
I have a bioinformatics pipeline that builds and runs .sh files in Python. I run the .sh through a subprocess module so I can use parallel computing.
This worked about 6 months ago, but now has ...
0
votes
0
answers
33
views
How to use gdal_translate in Python
I am trying to convert a netCDF file to a Cloud Optimized GeoTiff (COG) format. I have been able to do so successfully in the OSGeo4W Shell using the following command:
gdal_translate -of GTiff NETCDF:...
0
votes
1
answer
37
views
FLIR Lepton on RaspBerry Pi 5
I have a FLIR Lepton conected to a raspberry pi 5. I nned to start it from a python file.
I followed the groupgets github page to start the camera.
cd into /LeptonModule/software/raspberrypi_video.
...
1
vote
2
answers
60
views
Multiple inputs to subprocess.Popen
I have a program which requires 2 inputs to be passed.
How to achieve it using subprocess
import subprocess
pass1 = "welcome1"
pass2 = "welcome2"
session = subprocess.Popen("...
0
votes
0
answers
15
views
nohup output got truncated
I am working on a script to get output from a command for further actions.
I used subprocess to get the output and nohup to run the script in background.
The script run well with python python3 script....
1
vote
0
answers
72
views
Python subprocess function unable to load library
I am trying to execute a Java jar file via a subprocess.run() function in Python. When I execute the jar file via Java as normally performed a necessary library is found. In this case, the library is ...
0
votes
1
answer
55
views
Cryptic "OSError: [WinError 10106] The requested service provider could not be loaded or initialized" error from Python subprocess call
When porting some subprocess execution code from Linux to Windows, the Windows version failed with a Python traceback in the executed subprocess that reported OSError: [WinError 10106] The requested ...
2
votes
1
answer
33
views
Subprocess Task Is not teriminating in the `@celery_app.task`
I would like to stop the celery task using the celery ID. I am executing the subprocess task to run the spider for scrapping. So, when we stop the celery task the sub-process task also terminates.
But ...
0
votes
1
answer
45
views
Can't kill server running in subprocess - python
I am using the subprocess module. And using Popen to start the server subprocess.
# create a process for the server to run on
process = Popen("poetry run -vvv python ./app/server.py", cwd=&...
2
votes
1
answer
37
views
How to print the RAISE NOTICE output , if I am using subprocess along with psql?
I'm using postgres 16 remotely. The query loops to do a batch update and shows the loading percentage of the entire table with:
RAISE NOTICE 'Completion percentage: %', percentage_complete;
How do I ...
-1
votes
2
answers
109
views
Python subprocess - OSError: [Errno 7] Argument list too long: 'perl'
I have a Python script, which loops over an id list. Within a for loop, messages are downloaded from S3 bucket based on the particular id. Then a Perl script is called and the messages are decrypted ...
1
vote
3
answers
139
views
How do I remove characters in a list?
The following command when run in BASH cleans The Raven.
cat The_Raven.txt | gawk '{print tolower($0)}' | tr -d "\!\"#$%&'()*+,-./:;<=>?@[\\]^_\`{|}~"
The following command ...
0
votes
1
answer
33
views
printing output of subprocess.Popen in a pyQt5 Widget (realtime)
I checked every post regarding this issue and I found either very old posts (2011) or posts with solutions not working or fitting.
My "only" wish is to bring the output of Popen to a ...
0
votes
0
answers
26
views
In Pycharm is there a way to subprocess an executable and capture the output, as if you have Emulated Terminal enabled?
Solution:
I didn't realise I could run subprocesses detached.
This is my solution which allows you to use the standard pycharm console with debug, and access to unusual/blocked stdout/stderr ...
-1
votes
1
answer
27
views
splitting video into shots with ffmpeg from within python
After some searching, the following command works to split my input video into shots, and save the first frame from each shot.
ffmpeg -i input_vid.mp4 -filter:v "select='gt(scene,0.1)',showinfo&...
1
vote
2
answers
59
views
subprocess.run() with capture_output=True
I am very new to Python. I am trying to run some shell commands via Python's subprocess.run(). I would also like to capture the output of the shell commands. When I run the command with ...
0
votes
2
answers
66
views
PermissionError: WinError 5 , cant access msi afterburner app with subprocess
I am trying to create a python script to auto change profiles in my MSI Afterburner, but I am stuck in a PermissionError: [WinError 5] Access is denied error. I have tried to see if its a path/...
0
votes
0
answers
25
views
How to invoke a PlatformIO subprocess in a PyInstaller packaged app?
I have a Python project which (amongst other things) manages PlatformIO projects.
Since PlaformIO doesn't expose any API, I'm using the subprocess module like this (after installing the platformio ...
0
votes
1
answer
47
views
/bin/sh: docker: command not found when running a script from Python, but works in terminal [closed]
I'm trying to run Docker commands from a Python script using the subprocess module. However, I keep getting the error /bin/sh: docker: command not found. When I run the same command in the terminal, ...
0
votes
0
answers
19
views
Kill open Popen handles on Flask dev server restart
I have a Flask app that I'm using to serve a webapp, whose frontend is built using esbuild.
I've managed to configure the Flask server to start the esbuild process in development mode, and to ensure ...
0
votes
1
answer
27
views
Send error messages to catch with subprocess.check_output()
I'm writing a web app (app.py) that when calling an API, runs a python script (main.py).
I'm interested in two things:
Printing/logging the logs of main.py in real time to the console
Obtaining '...
0
votes
1
answer
64
views
Is there an in-between function or an Alternative to subprocess.Popen and subprocess.Run?
I'm creating a Python terminal on a Windows computer from scratch and I'm trying to sync the error commands and pipe them from either command prompt or Powershell which ever one the code is in. ...
0
votes
1
answer
166
views
Custom package install leads to subprocess.CalledProcessError -> No module named pip
Important(?) Details
Windows 10, version 10.0.19045
Python 3.12.2
PyCharm 2024.1 (Professional Edition)
GitBash 2.45.1.windows.1
The Setup
I'm trying to install pygraphviz with my package in a ...
0
votes
0
answers
25
views
Issues with reading and writing in process with adb console
I am trying to improve the read and write functionality. The task is to have console working while I receive outputs from commands I have send. The issue is I do not know when the response ended e.g. ...
0
votes
1
answer
17
views
How to ensure subprocess sees mock patched variable?
I have unit tests that look like the following:
with patch('my_module.file_in_module.SOME_GLOBAL_VARIABLE', new=mocked_var):
subprocess.check_call([
# CLI omitted
])
If I print ...
0
votes
0
answers
16
views
Installing Windows Service from frozen Python app
I've developed a Python app which installs and manages instances of a Windows Service (also developed in Python). The app works fine and I am now in the process of figuring out how to package it for ...
0
votes
0
answers
19
views
FileNotFound error when running Flask app with Supervisor
I'm encountering a FileNotFound error when running my Flask app with Supervisor. The code works fine when running the Flask app normally. Below is my Supervisor configuration and the Python code ...
0
votes
0
answers
46
views
Install Package in Chroot. Script running outside Chroot
I am trying to do a kind of analyzer. To do that I need to work with different distributions I decided on trying chroot. What im trying to do is,
using a python script on main machine
Go into chroot ...
0
votes
1
answer
60
views
What is the correct way to handle input prompts from Git using Python's subprocess? [closed]
I have a Python script that is responsible for backing up git repositories. It basically pulls a list of all repos in a org (Azure DevOps/GitHub) and clones all repos in that list.
The issue is that ...
0
votes
1
answer
34
views
Nothing happens after subprocess.stdout.readline() / subprocess.stdout.read()
From Python, I'm trying to control cmd in console, here is my code:
cmd_process = subprocess.Popen(["cmd"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding='...
0
votes
0
answers
36
views
How to handle two dependent tasks?
Let's say we have task A and task B.
B needs A's result in the middle of B's execution time, and B will wait for A's result by polling.
If A exits (due to failures), B can exit
before A exits (not ...
0
votes
0
answers
51
views
Run a command inside a WSL environment using python
I'm attempting to open a CMD, followed by launching WSL and executing some scripts within it. Initially, I'm aiming to print a 'hello world' message inside the WSL environment. However, I'm ...
0
votes
0
answers
26
views
'charmap' codec can't encode character '\u2713' in position 0: character maps to <undefined>
so im currently coding something with modal (modal.com) that uses python subprocesses to run these scripts, but well, everytime the modal subprocess starts, it gives me the error: "'charmap' ...
0
votes
0
answers
30
views
Unable to run sqlcmd via subprocess.Popen
I am trying to run SQL command using SQL file in Python
process = subprocess.Popen(shlex.split(command), stdout=log)
print("command: {}".format(command))
print("split cmd: {}"....
0
votes
1
answer
36
views
How to use Python multiprocessing and subprocess to run Pytype on different files in parallel?
I have thousands of Python files to run PyType on, which will take months. Thus, I am trying to use Python multiprocessing to create multiple processes and use each process to run PyType on a separate ...
0
votes
1
answer
36
views
Printing specific items from Python Shell
I have this code:
import subprocess
activescheme = subprocess.check_output('powercfg -getactivescheme')
print(str(activescheme, encoding='cp866'))
And this output:
GUID схемы питания: 22222222-2222-...
0
votes
1
answer
50
views
Command runs perfectly with shell=True but not if it is set to False
I am trying to run a npm command that in turn executes another package (cypress) like e2e: cypress run. If I run this in the terminal or with shell=True it works as intended for the same environment. ...