12,330 questions
1
vote
2
answers
98
views
Initialize interpeter before it runs main script
I need to run python script with costly initialization (0.5 seconds). To mitigate initialization time multiple interpreters are pooled, so when need to execute arises, interpreter is taken from pool ...
-3
votes
1
answer
60
views
Why mysqldump is returning cannot find table ">" in python subprocess [duplicate]
i have created a mini python tool to backup using mysqldump
import os
import subprocess
from datetime import datetime
from dotenv import load_dotenv,dotenv_values
load_dotenv(dotenv_path="./...
0
votes
0
answers
59
views
Powershell Terminal Struggling with Subprocess
im currently trying to call/run python file b from python file a and it works, although all terminals except cmd struggle to let me work within this new opened python file i.e. i can only seem to type ...
1
vote
1
answer
144
views
start_new_session in subprocess.Popen does not detach process in PyQt5 app?
So far I've seen:
Python spawn off a child subprocess, detach, and exit
Use the start_new_session parameter available since Python 3.2: [...]
This will allow the parent process to exit while the ...
-1
votes
1
answer
83
views
randomTrips.py hangs indefinitely on Windows; outputs written only after force termination
I’m building an agentic AI around SUMO using Python (TraCI + randomTrips.py) on Windows.
I’m facing an issue where randomTrips.py hangs indefinitely during traffic generation when executed ...
-1
votes
3
answers
190
views
Python subprocess failed with "is not recognized as an internal or external command"
I would like to automate a task of running an application repeatedly using Python's subprocess.
The application is called ltx, and I need to run it with the -h argument, for example:
[~]$ ltx -h
Note ...
0
votes
0
answers
86
views
DB2 CLP command via subprocess.run sometimes returns empty output and sometimes SQL1024N: A database connection does not exist
I'm running a DB2 stored procedure from Python using subprocess.run.
The command works perfectly when I run it directly in my shell:
db2 'CALL GET_DBSIZE_INFO(?, ?, ?, 0);' | awk -F': *' '/Parameter ...
2
votes
1
answer
73
views
subprocess.Popen wait doesn't seem to wait for Google Chrome on macOS
p = subprocess.Popen([
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
f"--remote-debugging-port={SOME_PORT_NUM}",
"--no-...
Best practices
1
vote
4
replies
148
views
Open Vim with text in it, without saving the file
I want to write a script which ends by calling my text editor (vim) on a specific file path. The file doesn't yet exist, and I want the editor window to already have some contents in it. In particular,...
0
votes
1
answer
182
views
Monitor `asyncio.create_subprocess_exec` pipes for errors
I am trying to pipe multiple Linux commands and abort if there is an error. With Popen the communicate() method waits for all commands to finish. This is why I am trying asyncio now.
I have the ...
0
votes
1
answer
87
views
subprocess cannot use stdout with CREATE_NEW_CONSOLE on windows
test.bat:
@echo off
for /L %%i in (40, -1, 10) do (
echo working %%i test1
ping localhost -n 2 > nul
)
echo Done!
main.py:
import subprocess
startupinfo = subprocess.STARTUPINFO()
startupinfo....
3
votes
2
answers
191
views
Cannot get command line code to run via python
I am running python 3.13.5 via PowerShell in windows 10. I can successfully run the folowing command, and now want to run it with a python script
& 'D:\realesrgan\realesrgan-ncnn-vulkan.exe' -i 'D:...
1
vote
0
answers
113
views
How to use multiprocessing with an asyncio process and a command line subprocess?
How would I be able to start a multiprocess when one of the tasks uses Asyncio and another task uses a subprocess to run?
Here is the main function:
import asyncio
import aioprocessing
import ...
0
votes
0
answers
110
views
Spawning a python subprocess and suppress output of it and its children
I'm running an utility for using kubernetes via the model context protocol. I can call it from the shell like this (using the uv tool utilities): uvx kubernetes-mcp-server --port 8080. I am spawning ...
-4
votes
1
answer
103
views
Executing an external python file with one out of several possible options
I am writing a PIN code system whereby a particular PIN code is assigned to a particular solenoid lock.
There are two files:
File1: This file has a function in it where it takes the user input (PIN) ...
0
votes
2
answers
101
views
threading.Thread cannot catch a PyCharm "stop" button termination event
I am using Pycharm. When I click the "stop" button, the subprocess.Popen deletes the left over .bat files. But after putting the subprocess.Popen inside a threading.Thread function, the .bat ...
-1
votes
0
answers
41
views
How do I talk to Python in a subprocess? [duplicate]
I would like to launch the Python REPL as a subprocess, but it doesn't appear to work:
import sys
import subprocess
p = subprocess.Popen([sys.executable], stdin=subprocess.PIPE, stdout=subprocess....
11
votes
4
answers
827
views
How to correctly pass a filename with a single quote to ffmpeg's subtitles filter in Python?
I'm writing a Python script using subprocess to hardcode subtitles onto a video. My code builds a complex filter graph for ffmpeg's -vf argument, which includes burning in multiple layers of styled ...
0
votes
1
answer
75
views
subprocess.run() eventually reaches python's global thread limit
I have a python script that pings another device every so often.
PING_SIZE = "1"
PING_RETRYS = "1"
while True:
try:
result = subprocess.run(
["ping&...
0
votes
0
answers
367
views
Problem launching chromium with remote-debugging-pipe from python
I was trying to launch chromium browser using remote-debugging-pipe in python,
but there is a problem everytime I tried to do so,
I am using this code,
I got help from gemini and chatgpt but they don'...
0
votes
0
answers
57
views
App start by debugger cannot trigger 'goto source code' by spawn code.exe
VS Code Version:
Version: 1.103.2 (user setup)
Commit: 6f17636121051a53c88d3e605c491d22af2ba755
Date: 2025-08-20T16:45:34.255Z
Electron: 37.2.3
ElectronBuildId: 12035395
Chromium: 138.0.7204.100
Node....
1
vote
1
answer
73
views
python 3 - stream subprocess.Popen output into variable
I made a batch file stopwatch.
temp1.bat
echo WAITED 3 SECONDS
timeout /t 3 /nobreak >nul
echo WAITED 5 SECONDS
timeout /t 5 /nobreak >nul
echo WAITED 6 SECONDS
timeout /t 6 /nobreak >nul
...
2
votes
2
answers
141
views
Why does ffmpeg command work in terminal but not subprocess.call
I reviewed the "similar questions", but those seem to refer to using the full path for ffmpeg to ensure using the same version, which I am already doing so posting my question.
I am using a ...
2
votes
1
answer
98
views
gdal2tiles.py hangs when run in Conda Docker environment
I'm running a Python script inside a Conda-based Docker container that processes geospatial data. The script runs a two step GDAL workflow, it uses gdaldem colorrelief to create a colorized GeoTIFF, ...
1
vote
0
answers
96
views
run powershell script with specific AppUserModelID from node.js
I have some powershell script/command I wish to run form a node.js environment. But since the command is dependent on the 'AppUserModelID' it seems to fail since the command spawns a separate program (...
2
votes
1
answer
101
views
Why am I getting an additional " at the very end of the subprocess.run stdout?
I am building a remote terminal with Python subprocess. Trying to capture the output and errors from subprocess.run(), and I'm having issues with an extra quote getting printed that should not be ...
2
votes
0
answers
130
views
Why does subprocess require two .readline() calls when shell=False, but only one with shell=True?
I'm writing a Python script that sends expressions to the bc command-line calculator using subprocess.Popen. I noticed a difference in behavior based on whether I use shell=True or not.
When using ...
0
votes
0
answers
58
views
How do I sucessfully stop TCPDump recording?
I am very new to python. My current project is to create a basic Tkinter window to start and stop a TCPdump Ethernet recording using a couple of buttons. I have been able to start a recording using a ...
2
votes
1
answer
57
views
Running a python script in the background, then passing an event to end it after a given amount of time
In short, I'm trying to run a python script from another python script but in the background, allowing the parent script to continue executing, and then to pass a CTRL_C_EVENT to the child script to ...
-1
votes
1
answer
104
views
Subprocess fails in PyInstaller package
I'm working on PyInstaller Packaging. But subprocess isn't seem to be working. Subrocess part it getting stuck and not getting further. But i'm getting return code 0 error.
Test.py
import pandas
...
1
vote
1
answer
67
views
subprocess.Popen terminate() not stopping batch file
The following code is supposed to stop the batch file counting down to ZERO when the KeyboardInterrupt error is called. But it is not doing so.
with open('test.bat', 'w', encoding='utf-8') as file:
...
-1
votes
1
answer
68
views
Python doesn't register change in timezone after being started
I have the a program running on a Raspberry Pi which, for the purpose of this question, can be boiled down to the following:
import datetime
import subprocess
#Change system timzone
subprocess.run('...
-2
votes
1
answer
76
views
subprocess.Popen making WSL 2 terminal inputs invisible [closed]
In my WSL 2 terminal, I am running a Python script that creates multiple subprocesses with Popen(<command>).
The command I am passing in executes a makefile in a Docker container. When the ...
1
vote
0
answers
58
views
Renaming files within 7z archive not working via Python script but does work via Bash
I have a fairly specific issue that I have been trying to solve for days to no avail. I have a Python script that opens archive files, decompresses them, and re-compresses them as zip files for ...
1
vote
1
answer
240
views
How to get power shell output from python
If I use the following Python code to get the output of PowerShell it works fine:
def get_powershell_table(command):
try:
result = subprocess.run(
["powershell", &...
0
votes
1
answer
78
views
Python setrlimit + subprocesses
I have a python program on which I wanted to set memory limits with setrlimit. But after setting the RLIMIT_AS, some things will stop working:
calling subprocesses
making http requests
def main(): ...
0
votes
1
answer
69
views
Multiple commands separated by newline in subprocess.Popen() with shell=True not working on Windows
I'm trying to execute commands on the shell via Python on Windows and Linux and noticed a significant difference:
import subprocess
r = subprocess.run("echo 1\r\necho 2", shell=True, ...
0
votes
1
answer
210
views
Issues with using subprocess.run for a Jupyter Notebook python file
I'm doing a data aggregation across multiple csv files. To save me some time, I have a python script developed that iterates through a series of subfolders and places a secondary script (called ...
2
votes
1
answer
49
views
subprocess.Popen batch file wont delete on force terminate
I want to run a batch file using subprocess.Popen … then delete the batch file if I force exit (the red square STOP button in pycharm)
with open('test.bat', "w", encoding='utf-8') as a: a....
0
votes
1
answer
87
views
Subprocess Fails When Tkinter "get()" uses cmd from Tkinter Entry Widget
process = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
For the above subprocess the cmd is:
cmd = ['/usr/bin/mkvmerge', '-o', 'temp', '--audio-tracks', '4', '/home/test/...
0
votes
1
answer
309
views
How to correctly pass Windows path with spaces to FFmpeg -vf ass filter in Python?
ass_path = r'C:\Users\username\Desktop\Title Of Video.ass'
command = [
'ffmpeg',
'-i', mp4_path,
'-vf', f"ass='{ass_path}'", # Embed the full ...
3
votes
2
answers
594
views
How can I run a background process and get the returned data in FastAPI?
I am using FastAPI to make a GET request, which runs a .jar file that returns some text data. The GET request is triggered by a button press in the frontend.
The Java program takes about 30 seconds to ...
1
vote
1
answer
112
views
Wrapping a python sub process
I would like to wrap an external process with a python subprocess to add a control on the input and output. I created a small wrapper program, and managed to change the input and output send to the ...
1
vote
1
answer
117
views
How could I self-eject my USB-Drive using the python module 'sub-process'
I have a script for my USB that i need to use on multiple devices, and i want it to auto-eject, and using this method, as long as it has elevated privileges it runs, no issues, no errors, but i check ...
0
votes
0
answers
102
views
Why does my first test run timeout (but second run does not) when running multiple Python scripts with ThreadPoolExecutor or ProcessPoolExecutor?
I am working on an automated grading tool for student programming submissions.
The process is:
Students submit their code (Python projects).
I clean and organise the submissions.
I set up a separate ...
1
vote
2
answers
94
views
Asyncio: read new data from process stdout without blocking monitoring task
I write asynchronous process manager, and up till now I came up with this:
import asyncio
class AsyncLocalProcessManager:
def __init__(self):
self.process = None
async def submit(...
1
vote
0
answers
93
views
TA-Lib Installation Fails in Google Colab: "Failed building wheel for ta-lib" Subprocess Error
I'm trying to install the TA-Lib Python package in Google Colab for a stock prediction project, but the installation fails with a subprocess error: ERROR: Failed building wheel for ta-lib. The error ...
2
votes
0
answers
73
views
Why does VS Code Debugger reset `PATH` from `.env`, breaking subprocess behavior in debug mode only?
I'm facing an unusual issue when using subprocess.Popen in Python while debugging in VS Code. The behavior of the PATH environment variable changes only in debug mode, and subprocess calls behave ...
1
vote
1
answer
51
views
Is there any way to show subprocess output in spyder console?
I'm computing neural networks with several .py files in spyder. I could sequencely execute them in spyder. However, the console do not show any thing like single file execution.
For example, this is ...
2
votes
1
answer
84
views
Executing an interactive command using ssh and Python
I want to use a Python script to ssh to a remote server I own and source a script called "admin_environment". The interactive part is required because I need to enter a password once this ...