Questions tagged [subprocess]

1

votes
2

answer
369

Views

Calling and executable with arguements and getting its STDOUT more efficiently in a Python Script

I'm writing a script that takes longitude and latitude and runs them through an executable called gdallocationinfo. The executable takes the latitude and longitude as its arguments and returns its STDOUT as the value for that coordinate. I've been reading about sub-processes and I was wondering if t...
Grant
1

votes
2

answer
1.2k

Views

writing large amount of data to stdin

I am writing a large amount of data to stdin. How do i ensure that it is not blocking? p=subprocess.Popen([path],stdout=subprocess.PIPE,stdin=subprocess.PIPE) p.stdin.write('A very very very large amount of data') p.stdin.flush() output = p.stdout.readline() It seems to hang at p.stdin.write() aft...
aceminer
1

votes
1

answer
652

Views

subprocess.CalledProcessError not giving error message

I am using below code for getting output of shell command. import subprocess exitcode, err, out = 0, None, None try: out = subprocess.check_output(cmd, shell=True, universal_newlines=True) except subprocess.CalledProcessError as e: exitcode, err = e.returncode, e.output print('x{} e{} o{}'.format(e...
1

votes
1

answer
42

Views

how to run command line in linux from another user

I need to execute a bash script from a python program (python2.7) in red hat, while this bash script has to run from another user account as splunk user. In the Linux, I will switch to splunk user su - splunk first, then type the command ./mybashFile under as a splunk user Here is what I tried: imp...
Field.D
3

votes
1

answer
32

Views

ffmpeg corruption when piping input from stdin

I have a program that generates images and creates a video out of them. Currently what works is creating all the images at once, then running FFmpeg in a subprocess and piping the images through stdin to create a video: cmd = ['ffmpeg', '-y', '-s', '{}x{}'.format(OUTPUT_WIDTH, OUTPUT_HEIGHT), '-r',...
CoconutFred
1

votes
0

answer
48

Views

python subprocess.call not finding specified file from windows task scheduler

I have a python script that uses subprocess.call() to call openssl, and it runs fine from command line. However, when I run through windows task schedule, the job fails with Winrror2 : specified file not found The same job runs fine from task scheduler when subprocess.call() is removed. I tried rep...
srajagopal
1

votes
0

answer
421

Views

Specifying encoding in Popen

In Python 3.6 you need to specify a string encoding in order to pass a string to the communicate() method. One approach is to set universal_newlines to True which, it seems, does some platform-specific magic to set the input to string. The other approach is to set encoding= to some value, though I...
Ray Salemi
1

votes
0

answer
63

Views

Why are atexit handlers not executed with subprocess, but os.system?

https://docs.python.org/3.6/library/subprocess.html#replacing-os-system states that os.system() can be replaced with subprocess.call(…, shell=True), but I've noticed two differences when calling a Python program with them: atexit is not triggered in case of using Ctrl-c with subprocess for the inn...
blueyed
1

votes
0

answer
85

Views

How to stop a process created by subprocess.run() method

This is my code, I wana stop the subprocess manully after the stdout content containning 'error' or 'completed'.How to stop a process created by subprocess.run() method. The software LATO is created by some other people and it never exit. I see the answer about using os.kill to kill child process...
Shannon
1

votes
0

answer
54

Views

Print commands executed by subprocess.call (subprocess.call trace)

My Pytnon script has a number of methods like: def clean_htmldir(self): super(Cov,self).clean0('rm -rf {:s}/*'.format(self.COV_HTMLDIR)) where clean0 is a method of the super class def clean0(self, rm_cmd): ret = subprocess.call(rm_cmd, shell=True) return ret Python script executes a number of shell...
Vladimir Zolotykh
1

votes
1

answer
95

Views

Subprocess Tornado capture exit status

Scenario: First, I need to update status in db to 'pending' and at the same time, return the status to user. Then subprocess will be running in the background and it will take 30 seconds as I have put time.sleep(30) in dummy.py. After that, I have to update status in db to 'completed'. I am trying t...
Austin
1

votes
0

answer
106

Views

After running subprocess.Popen or os.system or hardcoding the pi to take a picture, the code exits

Currently I am writing a script that will take a picture with a picam on my raspberry pi. But when I run my code it exits after I call the camera to take a picture. I have tried using subprocess.Popen(['sudo', 'raspistill', '-w', '320', '-h', '240', '-hf', '-o', '/home/pi/Documents/Python/robot1/im...
tteo57
1

votes
0

answer
281

Views

Problems Installing Javabridge with pip

When attempting to install Javabridge I get the following code dump/error message and have no idea where to go from here. I installed a whole bunch of visual studio packages and was able advance the situation from where I was last (Installing Javabridge With Pip Error) but have hit a standstill and...
EfelBaum
1

votes
0

answer
48

Views

Execute Multiple Python Script Files & Pass values for variables - Python 3.6

I am using below 3 variables in python script file. sourcePath, knoxPath, redShiftKeyFolderPath I want pass the values for these variable & execute them using below script. import sys, subprocess knoxPath = r'C:\sunil_plus\dataset\knoxFile.xlsx' redShiftKeyFolderPath = r'C:\sunil_plus\redShift' sour...
SPy
1

votes
0

answer
222

Views

Why returncode=0 and no stdout for my subprocess.run?

The simple python3 program named print-pid.py is running : cat print-pid.py import os from time import sleep print('my pid is',os.getpid()) sleep(1000) The output for python3 print-pid.py is : my pid is 5421 To get the pid with bash command. ps aux|grep 'python3 print-pid.py'|grep -v grep |awk '{...
scrapy
1

votes
2

answer
312

Views

Python Open XML and Save to CSV

I need to open an XML file and save it as a CSV. I am not interested in extracting contents (i.e. via lmtree). I just want Python to do what I would normally do (open the XML file in Excel and save as a CSV file). I know this can work to open the XML file in Excel: import subprocess subprocess.Pop...
Dance Party2
1

votes
1

answer
259

Views

Capture Ctrl-C Signal And Wait For Subprocess

I have a bit of python code in which I call a subprocess, and within the python script I want to capture the SIGINT signal, and wait for the subprocess to finish. Currently what I have kills the process when I ctrl-c. Any way to tell python to wait for the process to finish? Although I want to wait...
user2774695
1

votes
1

answer
312

Views

ssh via python subprocess.Popen: terminate if password requested

I'm using a python script to manage ssh fingerprint problems after a workstation(s) is reimaged. I attempt to connect with ssh, and if I get a any warnings I deal with them. However, if there are no errors, then I am asked for a password to connect. At this point I want to terminate the process. H...
43Tesseracts
1

votes
1

answer
51

Views

How to run a process and quit after the script is over?

I have asked a question how to run a clipboard clearing command from python, and I got a good answer for that: subprocess.run('xclip',stdin=subprocess.DEVNULL) subprocess.run(['xclip','-selection','clipboard'],input='') This seem to work in python, but there is a problem, it leaves the process open....
Markus84612
1

votes
0

answer
32

Views

subprocess fails to call a function

I am trying to call a function using subprocess.Popen as: proc = subprocess.Popen(['/usr/local/bin/qstat', '-u', 'rudrab'],stdout=subprocess.PIPE) numjobs = proc.stdout.read() which is giving error: Traceback (most recent call last): File 'genpos.py', line 159, in proc = subprocess.Popen(['/usr/loc...
BaRud
1

votes
0

answer
162

Views

Acquire process ID of a CMD shell opened with 'subprocess.Popen'

I am using subprocess.Popen in order to run some executable from the CMD shell: p = subprocess.Popen('cmd /c start app.exe') I am having problems closing the console window when killing CMD via p.terminate(). If I do it right away, then the console window doesn't even open. If I do it after some tim...
goodvibration
1

votes
0

answer
33

Views

How do i monitor a job that run for 3 days using python? Any suggested modules to be use here?

I have a scenario where I need to upload some huge files to a remote location and that runs for 3 days (700+ GB), here, all are command line activity and there is no UI or GUI to monitor it. How do I do it using some interesting and useful python modules? Any suggested modules would help here. Curre...
rk_12
1

votes
0

answer
207

Views

WINDOWS - python subprocess returns incorrect shell script exit code

Hi folks I'm a scripting/python newbie but i have searched endlessly for a solution to no avail. I am trying to call a sh script (using windows 10) using python (subprocess) and return the exit code to python. For clarity i have stripped out everything except the relevant code. I have an sh script...
Mike Waring
1

votes
1

answer
92

Views

Run a series of external commands in a Python script

I'm trying to run external commands (note the plural) from a Python script. I've been reading about the subprocess module and use it. It works for me when I have a single or independent commands to run, whether I'm interested in the stdout or not. What I want to do is a bit different: I want somethi...
Nicolas
1

votes
1

answer
82

Views

Python cmd command sfc /scannow

Hello so I'm trying to make a basic python script to execute cmd commands. The DISM command works fine, but when I try the sfc command I get the message: Windows Resource Protection could not start the repair service.' I am executing this script with admin privileges on cmd: import subprocess from...
Jake
1

votes
1

answer
266

Views

What linux user does a nodejs subprocess run as?

I'm trying to run a docker image using docker run as a nodeJS subprocess but I am getting the error: error:docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post http://%2Fvar%2Frun%2Fdocker.sock/v1.35/containers/create: dial unix /var...
thegalah
1

votes
1

answer
86

Views

Popen file descriptor difference between Python 2.6 and 2.7+ on Linux

I have a really odd problem. I have some code that requires a Linux file descriptor (/dev/fd/N) where N is some number. The following example code demonstrates effectively what is being done. In order to run the code create a file called '/tmp/test' with some text in it. The code works in Python 2.6...
Ace Gopher
1

votes
1

answer
25

Views

How to Pass a list of variables which are strings to stdout via subprocess.communicate

I can successfully hard code my values as follows below: (my app launches and the parameters are passed and it runs as if I hit enter after manually entering in each parameter as I would if I ran it via command line, inputting the parameters manually and hitting enter after each one): from subproces...
Sherri
1

votes
1

answer
53

Views

Execute python files from a list

I have made a search of python scripts in some subfolders using os.walk() and endswith(file.py), and put them in a list. Now I'm trying to execute them. So I have a list of the type: pylist = ['./1/file1.py', './2/file2.py', ...] and I have tried to execute them using a for loop: for i in range(len(...
JVR
1

votes
0

answer
300

Views

Getting a pandas DataFrame from a subprocess

I have a python 3 script that calls a sub process. Below is line of code I use in my script: Note: Path is my python exe file (the sub process is ran in 2.7 where as the main script is in python 3. The rest are some parameters passed to the sub process. Proc = subprocess.check_output([path,'ListProc...
Campo21
1

votes
0

answer
164

Views

subprocess check_output getting standard output: Broken pipe warning message

I have below command which executes Just fine when I am trying in Linux SuSE OS(I mean any warnings): supportconfig -R /tmp Same command I used in python using subprocess check_output Code: import os import sys from subprocess import check_output b = check_output(['supportconfig', '-R', '/tmp']) War...
meteor23
1

votes
1

answer
83

Views

Display stdout and stderr of subprocess seamlessly

There are a few other questions around dealing on how to print stdout and stderr of a subprocess. The final objective would be to run a command with the same output it would have on bash. I'm currently with something like this: with subprocess.Popen(['java', '-jar', 'myJar.jar'], env=dict(os.environ...
devster
1

votes
0

answer
65

Views

Popen polling blocking my stdout

To prove a concept to myself I wrote this code: from subprocess import Popen, PIPE import json queue = [] command1 = ['python', 'C:\Desktop\testing_popen\time_delay.py'] command2 = ['python', 'C:\Desktop\testing_popen\no_time_delay.py'] queue.append(Popen(command1, stdout=PIPE)) queue.append(Popen(c...
James Deehan
1

votes
1

answer
124

Views

Syntax error while using subprocess and Awk

Receiving this error when attempting to run a python script that is using Awk and Subprocess: awk: cmd. line:1: {if ($6 == +) print $1, $2-1000, $2+1000, $4, $5, $6; else print $1, $3-1000, $3+1000, $4, $5, $6} awk: cmd. line:1: ^ syntax error awk: cmd. line:1: {if ($6 == +) print $1, $2...
dddxxx
1

votes
0

answer
96

Views

Kernel error in Jupyter with cling

I have this problem. When I launch a c++17 notebook in jupyter, I get the kernel error. However, python3 notebook is working fine. I build cling as per the instructions given in https://github.com/root-project/cling From the trace it is clear that some file is missing but which one, that's unclear...
Vikas Gupta
1

votes
0

answer
88

Views

pythonw subprocess can't call another version of python

Before I start, some notes on my environment: python 2.7.14 installed through miniconda, macOS 10.13.3. The Problem I'm trying to write a data processing pipeline (call it analyze.py) in python which calls several different programs. One of those programs, EMAN2 uses its own python environment to ru...
jhopkins
1

votes
1

answer
487

Views

scipy.io.wavfile.read() the stdout from FFmpeg

After searching for a long time, I still cannot find the solution to use scipy.io.wavfile.read() to read the bytes from the stdout of FFmpeg 3.3.6. Here is the example code working perfectly. However, it needs to save a converted file to disk. import subprocess import scipy.io.wavfile as wavfile com...
Sean Wu
1

votes
1

answer
24

Views

Python socket subprocess connection reply nothing after a while

I'm using python socket to communicate with the backend service (BC as the following structure shows): spawn Popen NodeJS server ------- Python Subprocess ------ backend process A B C Every time when I start the socket, it works great - but...
zhastdoit
1

votes
1

answer
545

Views

Non-blocking read on subprocess output without flush() and new line

I have a program that I can't modify. This program print data to stdout WITHOUT flushing it or put \n inside and wait for input and so on. My question is how can I, from a Python script, print in real-time stdout and write into his stdin? I found some ways to write into his stdin without closing the...
Yann Razafimahefa
1

votes
1

answer
28

Views

running shell command using python subprocess [duplicate]

This question already has an answer here: Actual meaning of 'shell=True' in subprocess 5 answers why python's subprocess.Popen() behavior is odd when running shell command as string and as list? when should we pass shell command as string and as list? >>> import subprocess >>> p = subprocess.Popen(...
Murali Mopuru

View additional questions