subprocess

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

Passing command to the called script

Passing command to the called script Question: I would like to call a script named openseessp and then pass "source test.tcl" argument to this script. I tried with subprocess module but after it invoked openseessp it exits and then runs source test.tcl command. I need to run this without exiting the first (openseessp): subprocess.run([‘openseessp’, ‘source …

Total answers: 1

Python subprocess on Linux: no such file or directory

Python subprocess on Linux: no such file or directory Question: I am trying to get the install location of conda. This works fine on Windows: conda_path = subprocess.check_output(‘where anaconda’).decode("utf-8").strip() In a linux shell whereis conda works. os.system("whereis conda") returns zero. However, conda_path = subprocess.check_output(‘where anaconda’).decode("utf-8").strip() Fails with: FileNotFoundError: [Errno 2] No such file or directory: …

Total answers: 1