subprocess

Why won't subprocess.run take a list of arguments?

Why won't subprocess.run take a list of arguments? Question: I am running a script called mini_medsmaker.py, and in that script I am using subprocess.run to call another script called mini_mocks.py. I am using argparse to list my arguments, and this is the command I am running: subprocess.run(["python", "/path/to/mini_mocks.py", *vars(args).values()]) Whenever I run it, I get …

Total answers: 1

subprocess stdout without colors

subprocess stdout without colors Question: I am running a command line tool that returns a coloured output (similar to ls –color). I run this tool via subprocess: process = subprocess.run([‘ls –color’], shell=True, stdout=subprocess.PIPE) process.stdout.decode() But the result is, of course, with the color instructions like x1b[mx1b[m which makes further processing of the output impossible. How …

Total answers: 2

How to pass an escape slash to subprocess.run

How to pass an escape slash to subprocess.run Question: Trying to run command this from a Python script: gh api "/search/code?q=somecode" –jq ".items[] | { "file": .path, "repo": .repository["full_name"] } " by way of: output = subprocess.run( [ ‘gh’, f’api "/search/code?q={CODE}"’, ‘–jq ".items[] | {{ "file": .path, "repo": .repository[{}] }} "’.format(‘\"full_name\"’) ]) to no avail. …

Total answers: 1

Capture real time `stdout` and `stderr` when run a function in a process python

Capture real time `stdout` and `stderr` when run a function in a process python Question: I have a python function and want to run it as a separate process with multiprocessing package. def run(ctx: Context): print("hello world!") return ctx afterward running it as a separate process with the following script: import multiprocessing p = multiprocessing.Process(target=run, …

Total answers: 1

Same python commands take different time if called in different ways

Same python commands take different time if called in different ways Question: I have some data (bytes) represending a png image that come over a pyzmq socket from an executable running in the background. I transform these to a numpy array using the following command decoded = np.asarray(im.open(io.BytesIO(data))) When I do this from the command …

Total answers: 1

ssh-keygen empty output with subprocess.run and os.system in python3.10 on macOS Ventura 13.1

ssh-keygen empty output with subprocess.run and os.system in python3.10 on macOS Ventura 13.1 Question: I have been attempting to output a signed public key generated from ssh-keygen (CLI) using python and the ‘subprocess’ library. I’ve also tried the ‘os’ library with the same results. I’m really looking to understand why it isn’t doing what I …

Total answers: 1

Exception Handling with subprocess.run in Python

Exception Handling with subprocess.run in Python Question: I am trying to create a function that can run any shell command and return the stdout of that command, without worrying about any exceptions that could be thrown. When testing the code written below with incorrect commands like xyz testing, I get a FileNotFoundError rather that the …

Total answers: 1

Getting rid of extra printing in subprocess Python

Getting rid of extra printing in subprocess Python Question: I am trying to print my ip address using subprocess.run() in Linux. So , i wrote the following code: ip=subprocess.run(["ifconfig | grep -w ‘inet’ | awk ‘{print $2}’ | head -n 1"],shell=True,) It gives me my Ip address "192.168.1.103" in terminal , but i wrote it …

Total answers: 1

How to monitor subprocess's stdout in real time

How to monitor subprocess's stdout in real time Question: I have a subprocess that generate images. A main programe will consume images. My plan is to launch subprocess, monitor it. Once there are several images available (i.e. subprocess printed ‘2’ or ‘3’), I will start main programe. However, I fail to get ‘real-time’ output from …

Total answers: 1