Sponsored Content
Full Discussion: [Python] - subprocess issue
Top Forums Programming [Python] - subprocess issue Post 303038968 by scj2012 on Wednesday 18th of September 2019 12:13:28 PM
Old 09-18-2019
Quote:
Originally Posted by Yoda
It is also possible that the command that you are running is sending the output to stderr instead of stdout

Try this instead:-

Code:
subprocess.check_output(shlex.split(command), stderr=subprocess.STDOUT)

That doesn't work etiher. Also the exact same command works with subprocess.check_call. What's weird is the subprocess.check_output works in the python shell but not from the python script.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Doubt about pipes and subprocess

Hi, I am having a trivial doubt. Please see the below pipeline code sequence. command1 | (command 2; commend 3) I am aware that the command that follows pipe will run in the sub shell by the Unix kernel. But how about here? Since these set of commands are grouped under "parantheses", will... (6 Replies)
Discussion started by: royalibrahim
6 Replies

2. Shell Programming and Scripting

Crontab Permissions Issue with Python

I have a cron on a Linux server that isn't executing properly. CRON (with specific info replaced): MAILTO=emailaddress@server.com */2 * * * * python /data/site/cron.py OUTPUT: python: can't open file '/data/site/cron.py ': No such file or directoryAdditional info - The python path is... (3 Replies)
Discussion started by: theHire
3 Replies

3. AIX

Subprocess errors

Hi Guys, Just a question about subprocesses.. Lately one of our servers has started to throw out the following error: SYSTEM ERROR: Too many subprocesses, cannot fork. Errno=12 We've already increased the threshold twice. Its now up to 8000 and the swap space has also been increased. We... (6 Replies)
Discussion started by: Jazmania
6 Replies

4. Shell Programming and Scripting

python: what's wrong with my subprocess.Popen

my script is #!/usr/bin/env python import datetime import subprocess import sys import os import signal from time import sleep def runForAWhile(cmd, secs=10): print("running %s" % cmd) timeout = datetime.timedelta(seconds=secs) print timeout proc = subprocess.Popen(cmd,... (0 Replies)
Discussion started by: yanglei_fage
0 Replies

5. Shell Programming and Scripting

Python subprocess module

I need to run this command using python subprocess module (notice I'm using only variables): cmd = TESTPATH + ' -s ' + serviceName + ' -r ' + rdir + \ ' -m ' + masterAcct + ' -p ' + persona + ' -P ' + passwd (3 Replies)
Discussion started by: erick_tuk
3 Replies

6. Shell Programming and Scripting

Xterm using python subprocess

Hi, I am trying to run a shell script using subprocess in python. I can run simple script with arguments using subprocess.But I am not able to embed xterm in subrocess command. #!/usr/bin/python import subprocess subprocess.call() Above code gives me error. Please help me in... (2 Replies)
Discussion started by: diehard
2 Replies

7. Shell Programming and Scripting

Python subprocess

Hi guys, I'm learning python and perl and i was trying to run from python a perl script using the subprocess module. I have an issue that i don't understand regarding this. I run this code: #!/usr/bin/python import subprocess p2 = subprocess.Popen(,stdout=subprocess.PIPE) output2 =... (2 Replies)
Discussion started by: capitanui
2 Replies

8. Shell Programming and Scripting

Python Thread Execution Issue . . .

Greetings! I set up a basic threading specimen which does the job:#!/usr/bin/python import threading class a(threading.Thread): def __init__(self): threading.Thread.__init__(self) def run(self): print("thread a finished") class b(threading.Thread): ... (0 Replies)
Discussion started by: LinQ
0 Replies

9. Programming

Python[Issue in converting .py to .exe using py2exe

Hi Experts, Good morning. I am trying to convert my hello.py to hello .exe file. I followed the steps as mentioned in the documentation but getting errors in the end. Please help. What I did as below-- Created hello.py file print ("Hello world!") raw_input('') Then... (0 Replies)
Discussion started by: shekhar_4_u
0 Replies

10. Shell Programming and Scripting

Issue Spliting String in Python

I have a string like below Note: I have have a single to any number of comma "," seperated string assigned to jdbc_trgt variable. I need to split jdbc_trgt using comma(,) as the delimiter. I tried the below but it fails as i dont know how can i read each split string iterately. for... (4 Replies)
Discussion started by: mohtashims
4 Replies
Arch::Run(3pm)						User Contributed Perl Documentation					    Arch::Run(3pm)

NAME
Arch::Run - run subprocesses and capture output SYNOPSIS
use Gtk2 -init; use Arch::Run qw(poll run_async LINES); my $window = Gtk2::Window->new; my $label = Gtk2::Label->new; my $pbar = Gtk2::ProgressBar->new; my $vbox = Gtk2::VBox->new; $vbox->add($label); $vbox->add($pbar); $window->add($vbox); $window->signal_connect(destroy => sub { Gtk2->main_quit; }); $window->set_default_size(200, 48); $window->show_all; sub set_str { $label->set_text($_[0]); } my $go = 1; # keep progress bar pulsing Glib::Timeout->add(100, sub { $pbar->pulse; poll(0); $go; }); run_async( command => [ 'du', '-hs', glob('/usr/share/*') ], mode => LINES, datacb => sub { chomp(my $str = $_[0]); set_str($str); }, exitcb => sub { $go = 0; set_str("exit code: $_[0]"); }, ); Gtk2->main; DESCRIPTION
Arch::Run allows the user to run run subprocesses and capture their output in a single threaded environment without blocking the whole application. You can use either poll to wait for and handle process output, or use handle_output and handle_exits to integrate Arch::Run with your applications main loop. METHODS
The following functions are available: run_with_pipe, run_async, get_output_handle, handle_output, poll, wait, killall, observe, unobserve. run_with_pipe $command run_with_pipe $executable $argument ... Fork and exec a program with STDIN and STDOUT connected to pipes. In scalar context returns the output handle, STDIN will be connected to /dev/null. In list context, returns the output and input handle. The programs standard error handle (STDERR) is left unchanged. run_async %args Run a command asyncronously in the background. Returns the subprocesses pid. Valid keys for %args are: command => $command command => [ $executable $argument ... ] Program and parameters. mode => $accum_mode Control how output data is accumulated and passed to data and finish callbacks. $accum_mode can be one of RAW No accumulation. Pass output to data callback as it is received. LINES Accumulate output in lines. Pass every line separately to data callback. ALL Accumulate all data. Pass complete command output as one block to data callback. datacb => $data_callback Codeblock or subroutine to be called when new output is available. Receives one parameter, the accumulated command output. exitcb => $exit_callback Codeblock or subroutine to be called when subprocess exits. Receives a single parameter, the commands exit code. (Or maybe not. We have to handle SIG{CHLD} then. But maybe we have to do so anyway.) get_output_handle $pid Returns the STDOUT handle of process $pid. You should never directly read from the returned handle. Use IO::Select or IO::Poll to wait for output and call handle_output to process the output. handle_output $pid Handle available output from process $pid. ATTENTION: Call this method only if there really is output to be read. It will block otherwise. poll $timeout Check running subprocesses for available output and run callbacks as appropriate. Wait at most $timeout seconds when no output is available. Returns the number of processes that had output available. wait $pid Wait for subprocess $pid to terminate, repeatedly calling poll. Returns the processes exit status or "undef" if poll has already been called after the processes exit. killall [$signal] Send signal $signal (SIGINT if omitted) to all managed subprocesses, and wait until every subprocess to terminate. observe $observer Register an observer object that wishes to be notified of running subprocesses. $observer should implement one or more of the following methods, depending on which event it wishes to receive. ->cmd_start $pid $executable $argument ... Called whenever a new subprocess has been started. Receives the subprocesses PID and the executed command line. ->cmd_output_raw $pid $data Called whenever a subprocess has generated output. Receives the subprocesses PID and a block of output data. NOTE: $data is not preprocesses (e.g. split into lines). cmd_output_raw receives data block as if RAW mode was used. ->cmd_exit $pid $exitcode Called whenever a subprocess exits. Receives the subprocesses PID and exit code. unobserve $observer Remove $observer from observer list. perl v5.10.1 2005-10-08 Arch::Run(3pm)
All times are GMT -4. The time now is 05:50 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy