Subprocess.popen() should write to log without waiting for process to complete


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Subprocess.popen() should write to log without waiting for process to complete
# 1  
Old 05-28-2018
Subprocess.popen() should write to log without waiting for process to complete

Here is my test code
Code:
            process = sp.Popen(['make'] + [os.path.expandvars(item)
                                           for item in make_line],
                               bufsize=1,
                               universal_newlines=True,
                               stdout=sp.PIPE, stderr=sp.STDOUT,
                               cwd=src_home)
            output, _ = process.communicate()
            inner_logger_console.info(str(output.strip()))

I am trying with bufsize=0 or 1 to get near to real-time output in the logs. What I have to do? process.communicate() has to go right?
# 2  
Old 05-28-2018
What shell are you using to process this script?
# 3  
Old 05-29-2018
I got working solution
Code:
with sp.Popen(['make', '-C'] + [os.path.expandvars(item) for item in
                                            make_line],
                          bufsize=0,
                          stdout=sp.PIPE, stderr=sp.STDOUT,
                          cwd=src_home) as process:
                for line in process.stdout:
                    print(line.decode('utf-8').strip())

This User Gave Thanks to ezee For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Waiting for a process to complete in shell script

Hi, I need to initiate a process script which will start and do some processing and then shuts down. Then i need to other verifications. But the the process takes around 25 to 3o minutes. One thing i can monitor the nohup.out file for this process where i can wait for shutting down statement to... (3 Replies)
Discussion started by: Prashanth19
3 Replies

2. Windows & DOS: Issues & Discussions

AutoSys Job not waiting for script to complete

I'm not sure if this is the right place to post this issue...but here goes... I am converting a set of windows jobs from Control-M to AutoSys r11.3. The same command line is being executed in both systems. The Control-M job runs to compltion in about 1.5 hours, waiting for the entire batch... (3 Replies)
Discussion started by: ajomarquez
3 Replies

3. 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

4. Shell Programming and Scripting

Multiple process write to same log file at the same time

If we have 3 process to write to same log file at the same time like below. will it cause the data outdated because the multiple process writing same time? It this a safe way to keep the log for multiple process? p1 >> test.log &; p2 >> test.log &; p3 >> test.log & Thanks, (5 Replies)
Discussion started by: casttree
5 Replies

5. UNIX for Advanced & Expert Users

when a process fails to write to /dev/log

Hi , when a process fails to write to /dev/log ? (1 Reply)
Discussion started by: Gopi Krishna P
1 Replies

6. Solaris

Timed out waiting for Autonegotiation to complete

Received the Timed out message consistently when I tried to jumpstart an M5000 with: boot jsnet:speed=1000,duplex=full - install Made the error go away by adding link-clock parameter: boot jsnet:speed=1000,duplex=full,link-clock=master - install "link-clock=master" disables... (1 Reply)
Discussion started by: markoakley
1 Replies

7. Programming

parent not waiting until child complete executing another program through execl()

Hi, I am calling a program that greps and returns 72536 bytes of data on STDOUT, say about 7000 lines of data on STDOUT. I use pipe from the program am calling the above program. Naturally, I execute the above program (through execl() ) throught the child process and try to read the... (4 Replies)
Discussion started by: vvaidyan
4 Replies

8. UNIX for Advanced & Expert Users

Process(s) ID waiting on IO?

Hello Experts!! My CPU is waiting a lot (around 33%) on I/O. I would like to find out what process(s) are waiting on the i/o. Below is my real time output of vmstat and sar. Thanks for you help !!!! Regards Citrus OS: AIX - 5L : /u2/oracle >oslevel 5.3.0.0 : /u2/oracle... (9 Replies)
Discussion started by: Citrus143
9 Replies

9. Programming

using popen with background process

hi, how to work with a background process without a controlling terminal to make use of popen or system call ? when ever i use popen or system function call in foreground process, there is no problem with respect to that .. but when the same program is run as a background process without a... (7 Replies)
Discussion started by: matrixmadhan
7 Replies

10. Linux

waiting process

how to know the information of the waiting process how to calculate the time of the process that it has taken to execute i want to make a program that Should be able to keep a log of the processes expired(The log should contain the starting time, expiry time, time slices used, total execution... (2 Replies)
Discussion started by: shukla_chanchal
2 Replies
Login or Register to Ask a Question