subprocess

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

Popen.wait never returning with docker-compose

Popen.wait never returning with docker-compose Question: I am developing a wrapper around docker compose with python. However, I struggle with Popen. Here is how I launch launch it : import subprocess as sp argList=[‘docker-compose’, ‘up’] env={‘HOME’: ‘/home/me/somewhere’} p = sp.Popen(argList, env=env) def handler(signum, frame): p.send_signal(signum) for s in (signal.SIGINT,): signal.signal(s, handler) # to redirect Ctrl+C …

Total answers: 1

How to wait until a certain output (string) occurs while executing subprocess.check_output?

How to wait until a certain output (string) occurs while executing subprocess.check_output? Question: I am trying to write a Python script which will download my software build. So the script will wait until certain output occurs and proceed for the next task: import os import subprocess out = subprocess.check_output(["wget", "–downloadlink–"]) print(out) if "saved" in out: …

Total answers: 1

Execute terminal command over python

Execute terminal command over python Question: I’m trying to get the hostname where the .py is running, so I used: server = subprocess.Popen(["hostname"]) print(server.stdout) However, I’m getting this return: None HOSTNAME It always prints a None from the subprocess.Popen() and then the hostname at print(server.stdout). Is there a way to fix this? Asked By: null92 …

Total answers: 1

Unrecognized Option in subprocess.run()

Unrecognized Option in subprocess.run() Question: I want to run this command ebsynth -style source_photo.png -guide source_segment.png target_segment.png -output output.png. This works perfectly in cmd but not in python subprocess.run() Python Code import subprocess process = subprocess.run([‘ebsynth’, ‘-style’, ‘source_photo.png’, ‘-guide’, ‘source_segment.png target_segment.png’, ‘-output’, ‘output.png’], shell=True, cwd=dir) Running this I am getting error: unrecognized option ‘output.png’ What …

Total answers: 2

How to keep ROS publisher publishing while executing a subprocess callback?

How to keep ROS publisher publishing while executing a subprocess callback? Question: How can I keep the ROS Publisher publishing the messages while calling a sub-process: import subprocess import rospy class Pub(): def __init__(self): pass def updateState(self, msg): cmd = [‘python3’, planner_path, "–alias", search_options, "–plan-file", plan_path, domain_path, problem_path] subprocess.run(cmd, shell=False, stdout=subprocess.PIPE) self.plan_pub.publish(msg) def myPub(self): rospy.init_node(‘problem_formulator’, …

Total answers: 1

Python subprocess with dynamic variables and arguments

Python subprocess with dynamic variables and arguments Question: I want to ask how can I run subprocess.run() or subprocess.call() in python when the arguments are dynamic. I have already stored all commands in an external batch file, and I want to use Python to run the batch file after I update the arguments. I will …

Total answers: 1

python subprocess does not write the output

python subprocess does not write the output Question: I have the following code snippet as a Python script. I get the proper job output files with no errors. However the stdout subprocess log files (i.e. COSMOSIS_output_XXX.txt etc) don’t store the expected runtime logs. Instead, these files have <_io.TextIOWrapper name=9 encoding=’UTF-8′> as the only output written …

Total answers: 3

Python subprocess can't find Pythonpath module

Python subprocess can't find Pythonpath module Question: I am trying to use subprocess.run([‘python3.9’, "scripts/example.py"], check=True). example.py uses a module, that I have added to the PYTHONPATH. However, whenever I run the above line, the module is not found. The confusing part for me is, that printing sys.path inside of example.py I do see the path …

Total answers: 1