Questions tagged [subprocess]

1

votes
0

answer
128

Views

Get streaming output, error, allow user input with subprocess.Popen

I am trying to run a shell command thru python and get its output, error message and allow the user to input yes/no when asked. The command I and testing this with is cp dummy dummy2 -i Ideally I need a pythonic and up-to-date (python3.6) way that doesn't require additional software or libraries to...
samo
1

votes
0

answer
17

Views

Popen drops keys which don't start with a letter from env

I am having difficulty passing some environment variables to a process using Popen. Consider the following code snippet: from subprocess import Popen env = dict() env['VALID_VAR'] = 'some value' env['1INVALID_VAR'] = 'other value' proc = Popen(['./test'], env=env) I'd expect the new process to have...
Matan Shahar
1

votes
0

answer
120

Views

subprocess return '' (empty string) for command `docker exec`

handle.stdout.read() return '' (empty string) when the command is sudo docker exec -it $DOCKER_ID $SHELL_COMMAND. command = 'sudo docker exec -it %s ls %s' % (docker_id, ssh_dir) handle = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True) command_out = handle.stdout.read() But it can retu...
zzxwill
1

votes
0

answer
304

Views

CalledProcessError: Command [inputs] returned non-zero exit status 1.

I have been working in this code, to be more specific i am implementing an evolutionary algorithm following this link So is this my issue I use the function check_output in 2 differents parts of the code but I got two differents outputs check this out: wwnnnwwwwneeennen b'\r\n. . . . p . . \r\n...
Marcos Cruz
1

votes
1

answer
161

Views

RuntimeError with multiprocessing module when trying to recursively compare lists

I'm generating a list filled with sublists of randomly generated 0s and 1s, and then trying to compare each list with every other list to determine their similarity, efficiently. I know that my code works with a single process (i.e. without involving multiprocessing, but once I start involving multi...
Elliott Weaver
1

votes
0

answer
102

Views

How do I run and open a .py file in a tkinter gui in python

I have coded a gui with buttons and when I press one button I want it to run a .py script that displays a graph, so the graph has to open in a different view altogether. The .py file for the graph runs perfectly on its own but I am trying to implement it into my GUI upon clicking a button (I've used...
skcoder
1

votes
3

answer
84

Views

append to list function encodes german umlauts wrong

I want to iterate through some files within a folder and send the path of the files to a list. Then I want to pass this list to a subprocess to execute a bash command: procfiles = [] os.chdir('/path/to/directory') for root, dirs, files in os.walk('.'): for file in files: if '.mp3' in file: filename...
jones1008
1

votes
2

answer
24

Views

python Popen print the output of the external application and save it (log it) at the same time

I am trying to run an external application using Popen and print the output in the console or separated console (better) and at the same time save the output to the file. There is no user interaction via console, app.bat just sends (writes) the data and should terminate automatically when the execut...
Aleks
1

votes
0

answer
76

Views

Subprocess.Popen only runs second time

I have a boot controller which runs a boot.py file contained in each folder of each tool i am trying to deploy. I want my boot controller to run all of these boot files simultaneously. The config file has the tool names and the versions desired, which help to generate the path to the boot.py. def ru...
Peter Kentish
1

votes
1

answer
490

Views

How to pass arguments to subprocess

I want run a process called client.sh in gnome-terminal via python script and want to pass the arguments as input to execute it. Below is my code import os import subprocess import time from subprocess import Popen,PIPE import pexpect process = subprocess.Popen('sudo gnome-terminal -x ./client.sh'...
M.Girish Babu
1

votes
2

answer
76

Views

How to pass date arguments for requests.get command for API data?

I'm trying to get past weather data from API source. However I'm running into issues on how to pass the date arguments and specify dates I'm trying to get data for. I have been successful in using curl GET command, but not been successful in translating that over to requests.get command. Here's wha...
pewpewpew
1

votes
1

answer
71

Views

python subprocess.popen kill subprog when parent prog exits?

In python 2.7 if program master uses subprocess.Popen to start subprocess and then exits, subprocess will continue to run. I think that this is consistent with process handling in general, at least for *nix. This seems to imply that if some of my subprocess programs run forever and I kill master th...
WesR
1

votes
0

answer
53

Views

Setting an environment in subprocess to execute a batch file

I tried to set an environment with a *.sh file in a bash shell and then to execute a batch file with python subprocess. Here is my code: import subprocess p = subprocess.Popen('. ./bin/testenv.sh', ['start', '-b', 'cm.bat'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, exec...
mscm
1

votes
1

answer
51

Views

Combining 2 asyncio based code segments

I'm using the Autobahn asyncio system (to talk the Websocket WAMP protocol), which works fine and I can handle incoming RPC calls and pubsub. My problem is I now have to connect TCP sockets and send information over these sockets as soon as an RPC call comes in through the Autobahn part. The autobah...
wimg
1

votes
0

answer
142

Views

Process output of netcat and return back using python

I run netcat to listen to a server in a bash shell: nc domain.com 1234 The server outputs three numbers; I need to perform arithmetic on them and send the result back to the server. I have this code: #!/usr/bin/env python import subprocess nccommand = 'nc domain.com 1234 > ncoutput.txt' subprocess.P...
Adam Bromiley
1

votes
1

answer
619

Views

Understanding subprocess with a very simple example

Ok, im trying to understand how to use subprocess. I've made a little problem for practice and i just can't do it. what i want to do is: ping google then do a 'cd' command so basically i want to see the ping command return values and then the directory where my program is This maybe to much info, so...
wrong1man
1

votes
1

answer
112

Views

How to print variable value inside a function in shell script?

Below is my script in which I am putting value in a local_server variable depending on condition in case: #!/bin/bash servers=(machine981.abc.host.com luck123.pqr.host.com gond654.def.host.com) case $(hostname -f) in *abc.host.com) local_server=('${servers[0]}') ;; *pqr.host.com) local_server=('${se...
flash
1

votes
1

answer
17

Views

Python subprocess doesn't work with my find expression

This works in my terminal: find '/tmp/pic' \( -iname *.JPG \) | parallel -j 3 convert {} -resize 1920x -quality 60 '/tmp/pic2/{/}' This doesn't work with python: from subprocess import call import shlex call(shlex.split('find '/tmp/pic' \( -iname *.JPG \) | parallel -j 3 convert {} -resize 1920x -...
flowerflower
1

votes
1

answer
28

Views

How to run test command and get no exception in Python? [duplicate]

This question already has an answer here: OSError: [Errno 2] No such file or directory while using python subprocess in Django 1 answer If I run this test -d a in Linux command line, it returns nothing and prints no error even if directory a doesn't exist, because the result is returned via exit c...
Dims
1

votes
2

answer
56

Views

Using Popen in Python in ssh to Run “ls -lh INPUTS” Bash Commands

INPUTS is the variable I gave for the absolute path of a directory of possible input files. I want to check their status before going through my pipeline. So I tried: import subprocess import argparse INPUTS = '/home/username/WinterResearch/Inputs' status = subprocess.Popen(['ls', '-lh', INPUTS], sh...
rc341
1

votes
0

answer
21

Views

Python: Unicode error when passing password to sudo using subprocess.Popen.communicate

I have a tkinter Python 3 program that needs sudo privileges, so it checks for that and if you don't have it, it'll ask for your password and then rerun the program with sudo. My current code works when just running the code like, python3 myscript.py, but if I compile the script with python3 -m py_c...
FrailOtis
1

votes
1

answer
53

Views

Check every Minute if there was an *.odb file generated or not. If yes --> Get Data

I would like to check every minute if there was a file like 'RESULTS.ODB' generated and if this file is bigger than 1.5 Gigabyte there starts another subprocess to get the Data from this file. How can i make sure that the file isn´t in progress to be written and everything is included? I hope you...
Nils Kohlmey
1

votes
0

answer
76

Views

subprocess.Popen() doesn't redirect output to file

Check.cpp int main(int argc, char** argv) { string file = ''; ifstream inFile; int x; file = argv[1]; inFile.open(file.c_str()); while (inFile >> x) cout
kumar_123
1

votes
2

answer
52

Views

How to generate a string output with subprocess in Python3

I have a script that saves 5 seconds length of videos locally and it omits the file name. Here's the bash command ffmpeg -i http://0.0.0.0:8080/stream/video.mjpeg -vcodec copy -map 0 -f segment -segment_time 2 -loglevel 40 -segment_format mp4 capture-%05d.mp4 2>&1 | grep --line-buffered -Eo 'segment...
Perl Deniel
1

votes
0

answer
47

Views

Python wait for subprocess to finish before terminating

I am developing a python script that opens a program using the subprocess module and then using the pyautogui module to send keyboard shortcuts to the program. However, when the program opens and I send the CTRL + O shortcut to it, the program opens a file and then does some processing on that file....
kocon12
1

votes
0

answer
47

Views

Why there is no regex match in the output of this wget command?

I download a file from internet with wget and I want to record the name of the actual downloaded file (it changes in case the file already exists). I know that wget output goes to stderr, that is why I try to search for a regex match in it. There should be one but my 'match' is None (because I get t...
Stephane B.
1

votes
1

answer
12

Views

Python read from a newly written file does not work in module

I'm writing a python module that works on the files of the current directory. This is the code: import subprocess filename='tmp_file' #sends ls output to a temporary file with open(filename, 'w+') as f: subprocess.Popen(['ls', '-p'], stdout=f) f.seek(0) result = f.read() However result seems to be e...
1

votes
0

answer
58

Views

python: using tempfile as a pipe

TL;DR: how to get two INDEPENDENT file objects/descriptors of a tempfile (with no visible name)? I have lots of data and need to pass to a command to process, i.e. tmp = tempfile.SpooledTemporaryFile() p = subprocess.Popen(['command'], stdin=subprocess.PIPE, stdout=tmp) for d in get_data(): p.stdin....
Congbin Guo
1

votes
0

answer
131

Views

stdin.write() to cmd doesn't seem to be working. Any solutions to how to pass strings to command prompt?

I have looked at a lot of answers to stdin.write() issues and none have helped. I am trying to have my code change the password for an account through cmd but this requires the program to submit the password twice after I run mt =subprocess.Popen(['net','users', username, '*'], stdout = subprocess.P...
byo
1

votes
0

answer
164

Views

Python subprocess progress bar CLI

Some CLI(Command-line) programs such as flac.exe( downloaded here:https://xiph.org/flac/download.html ) display some sort of progress indicator(Progress bar/text) onto the console. In flac case, the program displays the progress using a percentage(audio.wav: 40% completed). Is there any way to captu...
TheRowdy
1

votes
0

answer
308

Views

cannot parse object when trying to reset git HEAD to last commit

I have a a subprocess command that runs on the server that reset git head to the last commit. like this args = [ 'git', 'reset', '--hard', str(self.commit_id), ] process = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=self.project_directory) stdout = process.communica...
Ciasto piekarz
1

votes
1

answer
239

Views

FASTQC runs on command line but not in python subprocess (Java exception)

The command line tool I'm using works fine when calling it from the Linux command line, but gives an exception when I am calling it via the Python subprocess module. I have looked at the previous posts relating to this, but none of them address how it would work on the command line but not in Pytho...
matnguyen
1

votes
0

answer
16

Views

proc.stderr.readlines() hangs with specific svn path

Python 3.6.5 This is my code for listing directory in svn. It works for most directories quite well, but with one path line error = proc.stderr.readlines() hangs forever (100% repeatable). Any ideas why or workaround on that? From terminal command works class MyRemoteSvnClient(object): def __init__(...
user2678074
1

votes
0

answer
61

Views

“Invisible Files” That Cannot Be Found Using Python For Loop

I'm trying to search through all the file in all sub-directories of my root directory to output lines that contain 'key_phrases' that the user input. My current code can find and output lines for most files in my sub directories, but I cannot seem to find lines in certain files of the folder, almost...
D. Wu
1

votes
0

answer
144

Views

remote debugging in pycharm, debugging a subprocess

Good Day! I have a script which runs on Python3.5, It spawns a subprocess which runs a java application. subprocess.run(['/usr/bin/java','-jar',]) This Java application internally invokes some of my python scripts which runs on Jython2.5. So I want to debug those Jython scripts, I'm enabling remote...
Murali
1

votes
2

answer
197

Views

subprocess msg command not working

I have been having some problems with subprocess.call(), subprocess.run(), subprocess.Popen(), os.system(), (and other functions to run command prompt commands) as I can't seem to get the msg command to work. import subprocess subprocess.call('msg * Hey',shell=True) In theory, this should send 'Hey'...
Hensage
1

votes
1

answer
393

Views

subprocess becomes defunct, `communicate()` hangs

In python 2.7 on Ubuntu 14.04, I launch a process like this: bag_process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) for i in range(5): print 'Countdown: {}'.format(5 - i - 1) time.sleep(1) print 'Sending SIGINT to PID {}'.format(bag_process.pid) bag_process.send_signal(s...
1

votes
1

answer
36

Views

How can I open an editor from a script in pycharm?

I'm trying to open an editor in the terminal in pycharm, running the script below and am getting the error: Error opening terminal: unknown. The EDITOR env var is set to /usr/bin/nano. The env var is being read correctly in the MVE below. I can open the editor if I call $EDITOR from the pycharm ter...
Jamie Bull
1

votes
0

answer
58

Views

Can't kill subprocess after waiting

I have a process running in a new Ubuntu shell, and I need to stop it after a certain period of time. My code looks like this: process = subprocess.Popen(args=['gnome-terminal', '--command=%s' % cmd]) print(process.pid) time.sleep(5) process.kill() This should, I would have thought, start the proces...
Bluefire
1

votes
0

answer
46

Views

Python using Popen to grab terminal output and print line with keyword

I am creating a function that will return the line output of my Popen with my keywords that I have set. Code i have so far: cmd = subprocess.Popen(['sudo dosfsck -w -r -l -v -a {}'.format(mountpoint)], shell=True, stdout=subprocess.PIPE, universal_newlines=True) keywords = 'difference' #want to add...
kkmoslehpour

View additional questions