FAQ Database Discussion Community


Unable to process python subprocess stderr on windows

python,windows,subprocess,stderr
I am trying to simple file copy operation using dd under Windows. The code is simple. Just open the command using subprocess and read stderr. Then process the stderr to show the progress of the operation. Here is the sample/simple code which I an trying to accomplish:- import time import...

Python use timeout for subprocess with Popen

python,timeout,subprocess,popen
Im running the following script with popen process = subprocess.Popen(['python', 'solver.py', 'newsudoku.csp', '-i', 'arc'], stdout=subprocess.PIPE) out, err = process.communicate() I need to process the output that is being stored in the out variable thing is this script varies in the time of its execution, and I need to kill it...

Calling eclipsec.exe to install p2 plugin using python and subprocess.call

python,eclipse,subprocess,p2
import subprocess print ("this is test installer") program = "C:\\ti\\ccsv6\\eclipse\\eclipsec.exe" command1 = "-application org.eclipse.equinox.p2.director -uninstallIU org.eclipse.(...).feature.group -destination C:\ti\ccsv6\eclipse -profile epp.package.cpp -noSplash" command_run = subprocess.call([program,command1]) This is the code I'm currently running to uninstall a plugin, and this particular line would work in command prompt. However if I use python, it...

Subprocess wait expect script to finish

python,subprocess
I'm calling the subprocess (expect script to run some command) and need to wait until it is finished to start another function, but with this I think it only wait until shell command is finihed, and not the expect script. Is it possible to wait for the whole process to...

python check_output fails with exit status 1 but Popen works for same command

python,subprocess,popen
Command framed to identify if Xcode is running on Mac: cmd = "ps -ax | grep -v grep | grep Xcode" If Xcode is not running, then above command works well with Popen method of subprocess module, but raises a CalledProcessError with check_output method. I tried to inspect the stderr...

ffmpeg subprocess fail to open on OS X

python,ffmpeg,subprocess
I've got this script: PATH = os.path.dirname(os.path.abspath(__file__)) global TEMP for video in os.listdir(VIDEOS): ffmpeg = PATH + "/ffmpeg/ffmpeg" arg1 = " -v 0 -i " arg2 = VIDEOS + "/" + video arg3 = " -r 1 -f image2 " arg4 = TEMP + "/" + os.path.splitext(video)[0] + "-%d.jpg" subprocess.Popen(ffmpeg...

Using subprocess.check_output for a command with 2>/dev/null

python,osx,subprocess
I am on Mac OS X Yosemite 10.10 and Python 2.7. If I type the following: du -g -d1 /Users 2> /dev/null in the command line, everything works perfectly. Now, my goal is to use that command in a python script. My idea was to use the following: import subprocess...

Python3 run os.popen with argument?

subprocess,popen,python-3.4
I am facing difficulties to run below query. Can some one help me to what is the issue on it ? def test(): cmd="python /home/shanaka/volapp/volatility-2.3.1/vol.py -f /home/shanaka/memory_sample/ubuntu-12.04-amd64-jynxkit.mem ---profile={0} {1}".format(OSselection.get(),option.get()) f1 = os.popen3(cmd) for lt in f1.readlines(): print(lt) This is not printing, Option.get is taking as another command, an error as...

python curl execute command with parameter

python,subprocess
I need to execute the following command curl -v -H 'X-Auth-User: myaccount:me' -H 'X-Auth-Key: secretpassword' http://localhost:8080/auth/v1.0/ when I run this from terminal it works perfectly. and gives me result like following * About to connect() to localhost port 8080 (#0) * Trying ::1... * Connection refused * Trying 127.0.0.1... *...

Getting an error in Python when trying to use stdin: io.UnsupportedOperation: fileno

python,python-3.x,subprocess
I am trying to std in an xml file. I read the xml file from subversion, updated a line in the file and now I am trying to create a jenkins job by using subporcess.Popen and stdin test = subprocess.Popen('svn cat http://localhost/svn/WernerTest/JenkinsJobTemplates/trunk/smartTemplate.xml --username admin --password admin', stdout=subprocess.PIPE, universal_newlines=True) job =...

Event Driven System Call in Python

python,progress-bar,subprocess,event-driven
I'm trying to implement an event driven process with system call or subprocess. Basically I want to launch a non-blocking system command and upon completion of that system call, I want a function to be called. This is so that I can start a GUI progress bar, launch a system...

Python Queue suddenly empty

python,python-2.7,subprocess,python-multiprocessing
I'm trying to run a couple of calculations concurrently based on this example. I extended it in the way that instead of just a simple function, I'm running some external software via subprocess. It's run with Python 2.7.6 on Ubuntu 14.04.2 LTS (GNU/Linux 3.16.0-30-generic x86_64). There is a Queue involved...

Run a setup.py from another Python script, path issue, installing in calling script dir?

python,subprocess,setup.py
First, I've found how to call a script from within an other script in Python, the call works perfectly well, but here's the problem I'm running into : In order to easy-install my web-app (Bottle) on an another server, I packed inside a /redist rep, with mod_wsgi and PyMySQL source...

Python subprocess call efficiency

python,subprocess
I am writing a python program which pings devices and reports online/offline status and latency. Right now it is working fine but whenever there are devices offline or not responding the output hangs for about 5 seconds. My question is can I either ping everything independently and not sequentially and/or...

Python subprocess echo a unicode literal

python,unicode,subprocess
I'm aware that questions like this have been asked before. But I'm not finding a solution. I want to use a unicode literal, defined in my python file, with the subprocess module. But I'm not getting the results that I need. For example the following code # -*- coding: utf-8...

Append output of multiple subprocesses to array in Python

python,arrays,subprocess
I'm working on a script in Python which open multiple subprocesses in this way: for file in os.listdir(FOLDER): subprocess.Popen(([myprocess])) Now this processes could be 10-20 running in parallel, and each of them will output in the console a single string line. What I want to do is to append these...

Python subprocess Messy output

python,subprocess
With the following code: output = subprocess.check_output(['wmic', 'PATH', 'Win32_videocontroller', 'GET', 'description']) print(output , "\n") I get the next output: b'Description \r\r\nNVIDIA GeForce 710M \r\r\nIntel(R) HD Graphics 4000 \r\r\n\r\r\n' When I use the commando wmic path win32_videocontroller get desriptionin my CMD I get only the videocard info back. Is this possible...

/usr/bin/which has strange behavior when called as python subprocess

python,python-2.7,path,subprocess,which
I have a python (2.7) package which depends on a library written in C (The brain imaging suite Freesurfer). In order to check for the library I wrote the following: def crash_if_freesurfer_not_found(): import os, subprocess with open(os.devnull) as devnull: p = subprocess.call(['which', 'mri_info'], stdout=devnull, stderr=devnull) if p!=0: print 'Useful error...

Redirect files from Popen to subdirecotry

python,redirect,subprocess,stdout,popen
I have a pipeline composed of a number of scripts. Almost all of the scripts read and write to files, and some of the scripts in the pipeline have conflicting file formats (they will read and attempt to perform actions on files that they should not due to the files...

Python 2.6: Get input from bash command with Popen and communicate and store as variable

python,bash,subprocess,popen
I need to get the input from a Bash command and store it as a Python variable (sprice; a single float). On Python 2.7 the following works well: bashCommand = "curl -s 'http://download.finance.yahoo.com/d/quotes.csv?s=vwrl.as&f=l1'" sprice = float(subprocess.check_output(bashCommand, shell=True)) However on Python 2.6 check_output isn't available. Instead we have to use: proc...

In python 2.6.6 when using subprocess.call , why can i not use glob pattern [duplicate]

python,subprocess,glob
This question already has an answer here: Problems with issuing cp command with Popen in Python 1 answer Python subprocess Popen: Why does “ls *.txt” not work? 2 answers I want to use glob pattern like this in subprocess.call function: >>> subprocess.call(["ls", "output*"]) ls: cannot access output*: No such...

Running a script from within a Python script

python,subprocess,os.system
I am attempting to run a python script located in a folder on my server from another python script. The location of the script I am attempting to run is not in the same location as the existing script. The script I am trying to execute is not a function...

How to stream subprocess output with a user prompt?

python,subprocess
Here's my subprocess call: def myrun(cmd): p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) stdout = [] while True: line = p.stdout.readline() stdout.append(line) print line, if line == '' and p.poll() != None: break return ''.join(stdout) When I run the 'cmd' normally, the output is usually something like: some text... some more text......

Pythonic way to detach a process?

python,subprocess,detach,etcd
I'm running an etcd process, which stays active until you kill it. (It doesn't provide a daemon mode option.) I want to detach it so I can keep running more python. What I would do in the shell; etcd & next_cmd I'm using python's sh library, at the enthusiastic recommendation...

subprocess - OSError [Errno 13] - although permissions seem ok - Python 2.7 / OSX

python,osx,python-2.7,subprocess
I am new to subprocess. When I run: subprocess.Popen(['/Applications/Calculator.app']) I get the OSError. When I check for the Calculator.app's permissions, they seem fine (drwxr-xr-x). It says 'wheel' instead of 'admin' or 'staff'. I am getting this Error with other apps too. On the other hand I can do: subprocess.call(['open', '/Applications/Calculator.app'])...

Python Subprocess Module: “Could not make directory”

python,subprocess,argparse
I have a Python script that takes in arguments from command-line using 'Argparser'. This is where I specify the location a particular file. Then, I invoke another command-line tool installed on my box, and pass on this location of the file to that tool. To function, the tool requires to...

Pipe result from subprocess to unix sort

python,subprocess,piping
I am calling a perl script on an external txt files from python, and printing the output to an outfile. But instead I want to pipe the output to unix's sort. Right now I am not piping, but are writing the output from the perl program first, then doing by...

'Communicate' in Python does not work

java,python,subprocess,popen,communicate
I'm trying to write a python program to test a java program that takes input from stdin using Scanner. All other posts point to using communicate with popen, but for me it absolutely does not work. When i run my python program, it just calls popen and then stops while...

Simultaneously reading stdin and writing to stdout in python

python,subprocess
I am new to threading so I feel as if I am missing an obvious point, but I couldn't find an previous question that pertained to this subject. I want to make a program that writes to stdin and reads stdout of a c program. This is the code in...

Using dd command through Python's subprocess module

python,subprocess,dd
Through Python's subprocess module, I'm trying to capture the output of the dd command. Here's the snippet of code: r = subprocess.check_output(['dd', 'if=/Users/jason/Desktop/test.cpp', 'of=/Users/jason/Desktop/test.out']) however, when I do something like print r I get a blank line. Is there a way to capture the output of the dd command into...

Detecting if a process exits cleanly with Python subprocess

python,subprocess,defunct
I wrote a python script that's responsible for executing other scripts. I do notice that every now and then, I get a defunct process. I was reading some other threads on StackOverFlow and they said that you can catch a problem if .communicate or .call aren't used. The only thing...

Subprocess reacts differently on SIGINT signals

python,linux,process,subprocess
b.py import subprocess f = subprocess.Popen(['python', 'a.py']) time.sleep(3000) a.py import time time.sleep(1000) Run python b.py, Press CTRL+C, both processes will terminate. However send the signal SIGINT to the parent process b.py, kill -2 xxxx, but the child process a.py remains....

Python 3.4.3 subprocess.Popen get output of command without piping?

python,linux,bash,subprocess,popen
I am trying to assign the output of a command to a variable without the command thinking that it is being piped. The reason for this is that the command in question gives unformatted text as output if it is being piped, but it gives color formatted text if it...

Using python to run different files (stata, .stc, etc), as you would a .bat on windows

python,batch-file,subprocess
In this guide to not being a total mess doing research, the authors talk about using a .py file to execute a directory in order -- that is, delete all the output files (.pdf, .txt, etc) and run just the .py and everything will be recreated from the raw data,...

How to collect output from a Python subprocess

python,subprocess,stanford-nlp,python-multithreading
I am trying to make a python process that reads some input, processes it and prints out the result. The processing is done by a subprocess (Stanford's NER), for ilustration I will use 'cat'. I don't know exactly how much output NER will give, so I use run a separate...

Exception handling when using Python's subprocess.Popen

python,exception-handling,subprocess
When dealing with open files, Python has the with syntax that makes sure the file closes when leaving the block - regardless of exceptions etc. with open('foo.txt') as f: foo = f.read() Since processes are resources too, I was wondering: is something similar possible or recommended when using Popen? For...

Subprocess module feeding new line character

python,python-3.x,subprocess
I'm writing a script that uses subprocess module to run the net time \\server windows command, and parse the output of that using regex. import datetime import subprocess import re myDate = datetime.datetime.now().strftime("%y-%m-%d") myTime = datetime.datetime.now().strftime("%H:%M") myDateTime = datetime.datetime.now().strftime("%y-%m-%d %H:%M") results_file = 'C:\\temp\\ServerTimes_{0}.txt'.format(myDate) servers_central = 'C:\\temp\\DMS-CENTRAL.txt' sql_central = 'gt2-dms1cst' def...

Start another program and leave it running when the script ends

python,python-2.7,subprocess
I'm using subprocess.Popen to launch an external program with arguments, but when I've opened it the script is hanging, waiting for the program to finish and if I close the script the program immediately quits. I thought I was just using a similar process before without issue, so I'm unsure...

maya python subprocess error

python-2.7,subprocess,stdout,maya
in python 2.7 i try this code to get data from Deadline software. Its return some data from server... import subprocess path = 'C:/Program Files/Thinkbox/Deadline7/bin/' p1 = subprocess.Popen([path + 'deadlinecommand.exe', 'pools'], stdout=subprocess.PIPE) p1.communicate() and see result: ('none\r\npool_01\r\npool_02\r\npool_03\r\npool_04\r\npool_05\r\npoolhalf\r\n', None) but when i copy that code to python in maya 2014 i...

Start a background process upon successful quickstart in cherrypy

python,rest,subprocess,cherrypy
I have a REST WebService built on top of cherrypy. The service goes online with the cherrypy.quickstart() call. I want to start a background process with subprocess.Popen() right after the service goes online. The cherrypy.quickstart() call is blocking. How can I add a callback to start the background process?...

How to run a line in Powershell in Python 2.7?

python-2.7,powershell,subprocess
I have a line of Powershell script that runs just fine when I enter it in Powershell's command line. In my Python application which I run from Powershell, I am trying to send this line of script to Powershell. powershell -command ' & {. ./uploadImageToBigcommerce.ps1; Process-Image '765377' '.jpg' 'C:\Images' 'W:\product_images\import'}'...

Parse the output of subprocess.call() from Python

python,python-2.7,subprocess
I am callign a webservice from my Python code : response = subprocess.call(['curl', '-k', '-i', '-H' , 'content-type: application/soap+xml' ,'-d', etree.tostring(tree), '-v' ,'https://world-service-dev.intra.aexp.com:4414/worldservice/CLIC/CaseManagementService/V1']) The service returns a soap message , how do I parse the soap message and find out if it was a failure or success? I tried to...

subprocess.Popen doesn't redirect output of the spawned process

python,subprocess,popen
I am having difficulty redirecting the output of a process created using subprocess.Popen to a file of my choice. The following is what I am doing: #popen_test.py import sys, os, subprocess, time, signal process_log = open('process.log','w') process = subprocess.Popen([<path_to_python_binary>,"process.py"], stdout=process_log, stderr=process_log, preexec_fn=os.setsid) #launching the sub process time.sleep(10) #waiting for sometime;...

Python subprocess return parameter

python,parameters,subprocess
What command must I use in Phyton to invoke a program and receive a parameter in return. Not a return "OK" or "not OK", but a returning identifier from the program that was invoked. I am using subprocess.call, but I know that not works. I am using Python 2.4.4....

Python kill parent script (subprocess)

python,subprocess
Im working on two scripts. One script is perpetually running. When it senses an update to itself, it will run the second script as a subprocess. The second script should kill the first script, implement the changes and run the updated script. However, I cant find a way to kill...

How to run in python subprocess without blocking parent process?

python,django,multithreading,sockets,subprocess
I know the questions is similar to: 1, 2 but answers for these questions didn't solve my problem. Workflow in nutshell: 1.Web application sends request to backend. (written in django) 2.Backend starts worker process, to do some job by calling: run_command = [sys.executable, my_python_worker, flags] logger.debug('Created os update process "%s"...

Filter out command that needs a terminal in Python subprocess module

python,terminal,subprocess,tty
I am developing a robot that accepts commands from network (XMPP) and uses subprocess module in Python to execute them and sends back the output of commands. Essentially it is an SSH-like XMPP-based non-interactive shell. The robot only executes commands from authenticated trusted sources, so arbitrary shell commands are allowed...

Python subprocess Log and Display in Shell Issues

python,subprocess
I have a python script where I'm running an external archive command with subprocess.Popen(). Then I'm piping stdout to a sys write and a log file (see code below), because I need to print and log the output. The external command outputs progress like "Writing Frame 1 of 1,000", which...

How to execute and save result of an OS command to a file [duplicate]

python,python-2.7,subprocess
This question already has an answer here: Python: How to Redirect Output with Subprocess? 4 answers In python 2.7, I would like to execute an OS command (for example 'ls -l' in UNIX) and save its output to a file. I don't want the execution results to show anywhere...

Multiple pipes in subprocess

python,pipe,subprocess,named-pipes
I am trying to use Sailfish, which takes multiple fastq files as arguments, in a ruffus pipeline. I execute Sailfish using the subprocess module in python, but <() in the subprocess call does not work even when I set shell=True. This is the command I want to execute using python:...

Python Reportlab multiple lines

python,pdf,subprocess,reportlab
I am trying to write my disk status to a pdf. The problem is it's failing in writing multiple lines: the text for each letter goes vertically. import subprocess from reportlab.pdfgen import canvas p = subprocess.Popen('df -h', stdout=subprocess.PIPE, shell=True) (disk, err) = p.communicate() print disk def hello(disk): height= 700 c...

Call python script with input with in a python script using subprocess

python-3.x,subprocess
I have a script a.py and while executing it will ask certain queries to user and frame the output in json format. Using python subprocess, I am able to call this script from another script named b.py. Everything is working as expected except that I am not able to get...

Terminating started Popen subprocess in Python

python,subprocess,popen
I am on Windows and I am starting a new process using subprocess.Popen that I want to terminate at a certain point. However, the gui that I initiated is still visible. A minimal example would be starting the PNG viewer: import subprocess proc = subprocess.Popen(['start', 'test.png'], shell=True) proc.kill() After the...

mocha-phantomjs output not shown when run with Python subprocess.check_output

python,subprocess,phantomjs,mocha,mocha-phantomjs
Guessing this is something to do with STDOUT/STDERR redirection, but the console output is not displayed when running #!/usr/bin/env python import subprocess subprocess.check_output('mocha-phantomjs static/js/tests/headless.html'.split()) The same command in the terminal prints out all the test output...

Hard kill a python sub-thread

python,multithreading,python-3.x,subprocess,kill
I have a python script that communicates with C++ program via shell commands. Python script makes calls to C++ program and gets responses through pipes. C++ program buffers output and blocks threads that read from pipes. I solved these problems using this class: import os import subprocess import threading import...

SBCL: Gather output of run-program process while running

subprocess,common-lisp,sbcl
Dear StackExchange members, I recently began toying around with Common Lisp and want to create a web interface for administrating a modded Minecraft server. I already tried out this solution but in this case the function just hangs and never returns. My code looks like this: (defvar *proc*) (defun create-minecraft-proc...

python3 subprocess in Oracle Linux (wget -o)

python-3.x,path,subprocess
I see there are several posts on python subprocess invoking bash shell commands. But I can't find an answer to my problem unless someone has a link that I'm missing. So here is a start of my code. import os; import subprocess; subprocess.call("wget ‐O /home/oracle/Downloads/puppet-repo.rpm https://yum.puppetlabs.com/puppetlabs-release-el-6.noarch.rpm"); When I do wget...

Pass Buffer to ChildProcess Node.js

javascript,node.js,image-processing,subprocess
Here I have on Node.Js where I want to do Image Processing in a Sub Process. As you will see I take the file image.jpg and want to write it back to hello.jpg in a subprocess: var node = require('child_process').spawn('node',['-i']); var fs = require('fs'); node.stdout.on('data',function(data) { var fs = require('fs');...

Running commands/programs with subprocess

python,subprocess
I am new to the subprocess module in python. The documentation provided this example: >>> subprocess.check_output(["echo", "Hello World!"]) b'Hello World!\n' What I tried is: >>> import subprocess >>> subprocess.check_output(["cd", "../tests", "ls"]) /usr/bin/cd: line 4: cd: ../tests: No such file or directory Traceback (most recent call last): File "<input>", line 1,...

/usr/bin/sleep causes poll object to block

python,subprocess
Using the following code, poll_obj.poll() blocks until sleep has completed: import select, subprocess, time, fcntl, os poll_obj = select.poll() popen_obj = subprocess.Popen("sleep 5", stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True, shell=True) fcntl.fcntl(popen_obj.stdout, fcntl.F_SETFL, os.O_NONBLOCK) fcntl.fcntl(popen_obj.stderr, fcntl.F_SETFL, os.O_NONBLOCK) poll_obj.register(popen_obj.stdout) poll_obj.register(popen_obj.stderr) start_time = time.time() poll_obj.poll() print(time.time() - start_time) It is my...

Why subprocess can't successfully kill the old running process?

python,subprocess,kill,terminate
I run a program test.py. Since it collapses frequently, I import subprocess to restart it when it stops. Sometimes I found subprocess can't successfully restart it. Hence, I force the program to restart every 60 minutes. But I find that there sometimes two test.py processing running simutanously. What's wrong with...

Launch two different scripts in two separate cmd windows using subprocess in python

python,qt,subprocess
I have a python GUI written with Qt using Python 3.4 as the current python version with two buttons. One launches a python script and the other launches a perl script. The Perl button launches this: subprocess.Popen(["ipy64.exe", "qadriver.py", arg1, arg2], stdin=subprocess.PIPE, shell=True) Python button launches this: subprocess.Popen(["perl.exe", "update.pl", arg], stdin=subprocess.PIPE,...

Working on many files with Python

python,linux,file,sqlite3,subprocess
The task: I am working with 4 TB of data/files, stored on an external usb disk: images, html, videos, executables and so on. I want to index all those files in a sqlite3 database with the following schema: path TEXT, mimetype TEXT, filetype TEXT, size INT So far: I os.walk...

Python prevent subprocess from consuming keypress

python,subprocess
I have a python script starting an .exe program in Windows. I want to be able to terminate this program by pressing "ESC". But I can't see the keypress in my Python program, it is read by the .exe program and consumed. How can I start the .exe program so...

How to run `pip` in a virtualenv with subprocess.Popen()?

python,windows,subprocess,virtualenv
I'm trying to launch a command in different Python virtualenvs using subprocess.check_call(). To activate the virtualenv (in a Python 2/3 agnostic manner), I simply append the path to my virtualenv bin (or Scripts under Windows) to the PATH and then call subprocess.check_call() with this modified environment. Like so: environment =...

Correctly getting return code when issuing command over SSH via subprocess

python,shell,ssh,subprocess
I'm trying to issue a command over ssh and get its return code via subprocess. I have some code that looks like this: cmd = 'ssh [email protected]_addr "some_command"' res = subprocess.check_output( cmd, shell=True, stdout=subprocess.PIPE) Now this works great if the cmd only generates an exit code (for instance, setting cmd...

Escaping string arugments to subprocess calls in Windows

windows,python-3.x,subprocess,clipboard
Why does Example one copy hello world to my clip board but not Example two? # Example one subprocess.check_output(["echo", "hello world", "|", "clip"], shell=True, stderr=subprocess.STDOUT) # Example two subprocess.check_output(["echo", "hello \n world", "|", "clip"], shell=True, stderr=subprocess.STDOUT) Another issues is that Example one copies hello world with quotes around it like...

How do I obtain the output from a program that uses screen redrawing for use in a terminal screen scraper?

python,subprocess,file-descriptor,pty
I am trying to obtain the output of a full-screen terminal program that uses redrawing escape codes to present data, and which requires a tty (or pty) to run. The basic procedure a human would follow is: Start the program in a terminal. The program uses redrawing to display and...

File gets created, but subprocess call says no such file or directory

python,subprocess
I am trying to redirect the output of a subprocess call to a file def get_arch(): global ip_vm in_cmd = "uname -p" with open('/home/thejdeep/arch_list',"w") as outfile: print outfile subprocess.call(in_cmd,stdout=outfile) print "Hello" for i in ip_vm: cmd = "ssh [email protected]"+i+" 'uname -p'" with open('/home/thejdeep/arch_list',"a") as outpfile: subprocess.call(cmd,stdout=outpfile) The file gets created....

Python subprocess input is read twice

python,io,subprocess,stdin
I need to wrap a program in python and feed it input and print output. But if it give it one line of input it seems to use this as input until the program terminates. I've written a very basic program in C (called inout) which takes in two lines...

Deadlock When Streaming From subprocess.Popen And Using Two Subcommands

python,python-3.x,streaming,subprocess,wsgi
In my wsgi application, I have to call a commandline tool to generate data and sometimes another commandline tool to convert that data. It all works through stdout/stdin. I'm using subprocess and I formerly used communicate, which worked fine but was slower since it's not streaming and trying to convert...

Python open and kill subprocess

python,subprocess
I'm working on Widnows 7 (32 bits) and this is my code: def start_mviewer_broker(broker_path, test_name): """ The function starts the broker server""" try: print("**** start_mviewer_broker ****") p = subprocess.Popen('start python ' + broker_path + ' ' + test_name, shell=True) return p except: print("**** start_mviewer_broker - EXCEPTION ****") return 0 def...

Python subprocess: pipe an image blob to imagemagick shell command

python,image,shell,imagemagick,subprocess
I have an image in-memory and I wish to execute the convert method of imagemagick using Python's subprocess. While this line works well using Ubuntu's terminal: cat image.png | convert - new_image.jpg This piece of code doesn't work using Python: jpgfile = Image.open('image.png'); proc = Popen(['convert', '-', 'new_image.jpg'], stdin=PIPE, shell=True)...

How can I effectively test my readline-based Python program using subprocesses?

python,unit-testing,python-3.x,subprocess,readline
I have a Python program, which, under certain conditions, should prompt the user for a filename. However, there is a default filename which I want to provide, which the user can edit if they wish. This means typically that they need to hit the backspace key to delete the current...

Print stdout and stderr with popen and subprocess in python

python,subprocess
I have a script in python that uses subprocess and comunicate() but I don't succeed to access to the stdout and stderr. When I use only the stdin the script works well. This is the part of the script: proc = subprocess.Popen(["./a.out"], shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, ) def inp(self,txt): f=open(txt,"r")...

Python SIGTERM not killing subprocess

python,subprocess,kill
I have a class which can start and close a process. However it seems not to close the process. My python code, there are other methods but they work fine.: class KismetInstance: """Creates a kismet_server instance""" def __init__(self, value=False): logging.basicConfig(format='%(asctime)-15s::: %(message)s') self.logger = logging.getLogger('kismet_instance') self.example = value def __create_kismet_instance__(self): """...

PYTHON subprocess cmd.exe closes after first command

python,cmd,subprocess,stdout,stdin
I am working on a python program which implements the cmd window. I am using subproccess with PIPE. If for example i write "dir" (by stdout), I use communicate() in order to get the response from the cmd and it does work. The problem is that in a while True...

calling nmap from pythons subprocess module using check_output function is not working

python-2.7,subprocess,nmap
I want to use a python script to use nmap. I realize there is a package for python-nmap. But I want to create a simple script that interprets the output of nmap command then does some more things depending on it's output. Attempting to use check_output("nmap") like this link does:...

Use NamedTemporaryFile to read from stdout via subprocess on Linux

python-2.7,subprocess,temporary-files
import subprocess import tempfile fd = tempfile.NamedTemporaryFile() print(fd) print(fd.name) p = subprocess.Popen("date", stdout=fd).communicate() print(p[0]) fd.close() This returns: <open file '<fdopen>', mode 'w' at 0x7fc27eb1e810> /tmp/tmp8kX9C1 None Instead, I would like it to return something like: Tue Jun 23 10:23:15 CEST 2015 I tried adding mode="w", as well as delete=False, but...

subprocess call to setup crontab

python,cron,raspberry-pi,subprocess
I'm trying to use a subprocess call in python to add a cron job entry: from subprocess import call call(["(crontab -l; echo '* * * * * ls -l | tee tresults.txt') | sort - | uniq - | crontab - "]) And I don't know what I'm doing wrong!...

parameter error in python script & TOR proxy server

python,sockets,subprocess,tor,proxy-server
I am Noob in Python. My Boss instructed me to run this python script with TOR proxy server running. He told me to pass this parameter this way: python DownloadYP.py /Users/myfolder/ japan http://www.jpyellow.com/company 1 222299 He configured it on MAC. I am using windows. So my parameter is this way:...

How to set parent process' shell env from child process

python,shell,subprocess,inter-process-communicat
The child process has a value which must be passed onto the parent process. I am using python's subprocess.Popen to do that, but child process's TEMP_VAR is not visible from the parent's shell? import subprocess import sys temp = """variable_val""" subprocess.Popen('export TEMP_VAR=' + temp + '&& echo $TEMP_VAR', shell=True) //prints...

Escaping in Python subprocess for sed command

python,unix,sed,subprocess
I am using Python to do sed delete / replace with the help of the subprocess. Somehow I am not getting the number of escapes correct. Here is my code: from subprocess import call remover = ["sed", "-i", "'1d'", "file"] call(remover) removeq = ["sed", "-i", "'s/\"//g'", "file"] call(removeq) Both of...

Difference in executing command with subprocess

python,subprocess
I have this piece of code that executes well: import subprocess exe_cmd = subprocess.Popen(["ls", "-al"], stdout=subprocess.PIPE) output, err = exe_cmd.communicate() print output And I have another piece where I assign the command to a variable and then pass it as argument. But in this case it fails. Why? import subprocess...

Python error when executing shell script

python,shell,subprocess
I'm executing a line of shell script using python. It isn't working with which to test of the existence of homebrew #!/usr/bin/python import sys, subprocess subprocess.call(["which python"]) throws the long error Traceback (most recent call last): File "installations.py", line 5, in <module> subprocess.call(["which python"]) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 522, in call...

Python subprocess throws [Errno 2] No such file or directory, error generated only when it on a remote host

python,linux,ssh,subprocess,python-2.6
I'm running python 2.6. I'm getting the subprocess throws [Errno 2] No such file or directory only when I run the script via ssh. For example, if I run the script manually on the machine, there are no errors, but if I do ssh hostname script.py --host hostname it generates...

Using subprocess with script using another version

python,subprocess
Can I use a script written in python 3.3 with the subprocess function to create a pipe between my script and another written in 2.7 ? If the answer is yes should I be doing something like this? import subprocess output = subprocess.check_output(['scriptInV2.7.py', '-arg1', '-arg2']) myFunctionInV3.3(output) I am pretty new...

Processing file paths with parentheses with Python subprocess

python,linux,bash,subprocess
The paths of the files I want to process contain parentheses in them. path = "/dir/file (with parentheses).txt" I'm trying to process them in Python as follows: subprocess.call("./process %s" % path, shell=True) However, I get the following error /bin/sh: 1: Syntax error: "(" unexpected How can I pass the correct...

Error calling LibreOffice from Python

python,subprocess,converter,libreoffice
Calling LibreOffice to convert a document to text... This works fine from the linux command line: soffice --headless --convert-to txt:"Text" document_to_convert.doc But I get an error when I try to run the same command from Python: subprocess.call(['soffice', '--headless', '--convert-to', 'txt:"Text"', 'document_to_convert.doc']) Error: Please reverify input parameters... How do I get...

python3 - subprocess with sudo to >> append to /etc/hosts

python,subprocess
I've been wrestling with solutions from "How do I use sudo to redirect output to a location I don't have permission to write to?" and "append line to /etc/hosts file with shell script" with no luck. I want to "append 10.10.10.10 puppetmaster" at the end of /etc/hosts. (Oracle/Red-Hat linux). Been...

How to execute a string containing a script using python subprocess module

python,shell,subprocess
I receive a script in a string and trying to find a way to execute it using the subprocess module of python. e.g. import subprocess script = """#!/usr/bin/python print "inside script" """ subprocess.Popen(script) This throws an OSError: saying there is no such file or directory, which is fair enough as...

use command `osascript -e 'quit app “Quicktime Player 7”'` with python

python,subprocess,popen,quicktime,osascript
I am using osascript -e 'quit app "Quicktime Player 7"' in OSX Terminal to close the Quicktime Player 7 application, which works well, but can't get this same command working using python. What am I doing wrong? This just runs, but does nothing: command = ['osascript', '-e', 'quit app', 'Quicktime...

Terminate all subprocesses if any one of subprocess has error

python,subprocess
I am trying to run two subprocesses simultaneously. My current program looks like if one of subprocess has error and terminated, it cannot relaunch again after 1 min. It needs to wait another subprocess failed also and both of them start together. I found some posts about how to kill...

Error opening ffmpeg subprocess in Python

python,ffmpeg,subprocess
What I want to do is opening a ffmpeg process in Python. My code look like this: import subprocess import os def Main(): ffmpeg = "C:\ffmpeg\bin\ffmpeg.exe" args = " -i C:\video.mp4 -r 1 -f image2 C:\FRAMES\frame-%03d.jpg" subprocess.Popen(ffmpeg + args).wait() Main() But even in this simple form I got always the...

Python subprocess.Popen() error (No such file or directory)

python,subprocess,system,popen
I am trying to count the number of lines in a file using Python functions. Within the current directory, while os.system("ls") finds the file, the command subprocess.Popen(["wc -l filename"], stdout=subprocess.PIPE) does not work. Here is my code: >>>import os >>>import subprocess >>>os.system("ls") sorted_list.dat 0 >>>p=subprocess.Popen(["wc -l sorted_list.dat"],stdout=subprocess.PIPE) File "<stdin>", line...

subprocess python 3 check_output not same as shell command?

python-3.x,subprocess
I am trying to use the subprocess module in python but its a bit tricky to get working. Here's my code import sys import os import subprocess import shlex def install_module(dir_path, command): c = shlex.split(command) os.chdir(dir_path) try: p = subprocess.check_output(c, shell=True) except subprocess.CalledProcessError as e: #print('install failed for: ' +...

Why does ln from Python subprocess fail while it succeeds from normal command line?

python,bash,subprocess,exit-code,ln
As the title says: >>> from subprocess import check_output >>> check_output(['ln', '~/other_folder/src/models/sc_models.py', './src/models/sc_models.py']) Traceback (most recent call last): File "<input>", line 1, in <module> File "/usr/lib/python2.7/subprocess.py", line 573, in check_output raise CalledProcessError(retcode, cmd, output=output) CalledProcessError: Command '['ln', '~/other_folder/src/models/sc_models.py', './src/models/sc_models.py']' returned non-zero exit status 1 >>> exit() $ ln...

Python subprocess.check_output(args) fails, while args executed via Windows command line work OK

python,cmd,subprocess
Some problems with python subprocess.check_output. output = subprocess.check_output(args) where my args is: args = "C:\\DO\\bin\\Config.exe --ChCfg7 --LFE -b1152000 C:\\DO\\PCM\\1.wav C:\\DO\\PCM\\2.wav C:\\DO\\PCM\\3.wav C:\\DO\\PCM\\4.wav C:\\DO\\PCM\\5.wav C:\\DO\\PCM\6.wav --ModeBCast -oC:\\DO\\OUT\\outfile > C:\\DO\\OUT\\log.txt This works when executed from standard windows command line, but doesn't work when executed via Python subprocess.check_output. In win cmd case there...

Reading lines of a file into a subprocess in Python

python,python-2.7,subprocess,nmap
So I'm trying to read a list of IP addresses from a .txt into a subprocess (Nmap) in Python. It's also worth asking if the problem could be the use of quotes or not. Here's the code: addressFile = raw_input("Input the name of the IP address list file. File must...

Process in python - fetch stdout of non-terminating process

python,subprocess,stdout
Suppose there is a program that produces different outputs with different inputs, and terminates if the input is a specific value. For example, it can be written in C++: int main() { int i; while(true) { cin >> i; if (i) cout << i << endl; else break; } return...