popen

how to prevent fgets blocks when file stream has no new data.

I have a popen() function which executes "tail -f sometextfile". Aslong as there is data in the filestream obviously i can get the data through fgets(). Now, if no new data comes from tail, fgets() hangs. I tried ferror() and feof() to no avail. How can i make sure fgets() doesn't try to read data when nothing new is in the file stream? ...

What is wrong with this _popen / select example?

UPDATE: i updated the code and problem description to reflect my changes. I know now that i'm trying a Socket operation on nonsocket. or that my fd_set is not valid since: select returns -1 and WSAGetLastError()returns 10038. But i can't seem to figure out what it is. Platform is Windows. I have not posted the WSAStartup part. in...

What's the difference between all of the os.popen() methods?

I was looking at the Python documentation and saw that there are 4-5 different versions of popen(), e.g. os.popen(), os.popen2(), etc. Apart from the fact that some include stderr while others don't, what are the differences between them and when would you use each one? The documentation didn't really explain it very well. ...

Python: How do I generate a keypress?

I am opening a process (with os.popen() ) that, for some commands, detects certain keypresses (e.g. ESC - not the character, the key). Is there a way to send keypress events to the process? ...

Launch a shell command with in a python script, wait for the termination and return to the script

I've a python script that has to launch a shell command for every file in a dir: import os files = os.listdir(".") for f in files: os.execlp("myscript", "myscript", f) This works fine for the first file, but after the "myscript" command has ended, the execution stops and does not come back to the python script. How can I do? Do ...

Python, Popen and select - waiting for a process to terminate or a timeout

I run a subprocess using: p = subprocess.Popen("subprocess", stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdid=subprocess.PIPE) This subprocess could either exit immediately with an error on stderr, or keep running. I want to detect either of these condition...

Prevent Python subprocess from passing fds on Windows?

Python's subprocess module by default passes all open file descriptors to any child processes it spawns. This means that if the parent process is listening on a port, and is killed, it cannot restart and begin listening again (even using SO_REUSEADDR) because the child is still in possession of that descriptor. I have no control over t...

ZipFile complains, is there a way around using the zipfile module?

Hi, I am trying to decompress some MMS messages sent to me zipped. The problem is that sometimes it works, and others not. And when it doesnt work, the python zipfile module complains and says that it is a bad zip file. But the zipfile decompresses fine using the unix unzip command. This is what ive got zippedfile = open('%stemp/tempf...

intercepting stdout of a subprocess while it is running

if this is my subprocess: import time, sys for i in range(200): sys.stdout.write( 'reading %i\n'%i ) time.sleep(.02) And this is the script controlling and modifying the output of the subprocess: import subprocess, time, sys print 'starting' proc = subprocess.Popen( 'c:/test_apps/testcr.py', shell=True, stdin=su...

kill a process started with popen

After opening a pipe to a process with popen, is there a way to kill the thread that is started? Using pclose is not what I want because that will wait for the thread to finish, but I need to kill it. ...

Python persistent Popen

Is there a way to do multiple calls in the same "session" in Popen? For instance, can I make a call through it and then another one after it without having to concatenate the commands into one long string? ...

Python Popen, closing streams and multiple processes

I have some data that I would like to gzip, uuencode and then print to standard out. What I basically have is: compressor = Popen("gzip", stdin = subprocess.PIPE, stdout = subprocess.PIPE) encoder = Popen(["uuencode", "dummy"], stdin = compressor.stdout) The way I feed data to the compressor is through compressor.stdin.write(stuff...

Python, redirecting the stream of Popen to a python function

Dear all, I'm new to python programming. I have this problem: I have a list of text files (both compressed and not) and I need to : - connect to the server and open them - after the opening of the file, I need to take his content and pass it to another python function that I wrote def readLogs (fileName): f = open (fileName, 'r') inStr...

Python's subprocess.Popen returns the same stdout even though it shouldn't

I'm having a very strange issue with Python's subprocess.Popen. I'm using it to call several times an external exe and keep the output in a list. Every time you call this external exe, it will return a different string. However, if I call it several times using Popen, it will always return the SAME string. =:-O It looks like Popen ...

popen() in C

I can run the following command xwd -root | xwdtopnm | pnmtojpeg > screen.jpg in a terminal under linux and it will produce a screenshot of my current screen. I try to do the following with the code: #include <stdio.h> #include <stdlib.h> int main() { FILE *fpipe; char *command="xwd -root | xwdtopnm | pnmtojpeg"; char line[2...

Popen log management question

Problem: I have a monitor program in Python that uses subprocess' Popen to start new processes. These processes have the potential to run for a very long time (weeks-months). I'm passing a file handle to stdout variable in Popen and I'm worried that this file will get huge easily. Is there a way I can safely move or remove the data i...

How do I get 'real-time' information back from a subprocess.Popen in python (2.5)

I'd like to use the subprocess module in the following way: create a new process that potentially takes a long time to execute. capture stdout (or stderr, or potentially both, either together or separately) Process data from the subprocess as it comes in, perhaps firing events on every line recieved (in wxPython say) or simply print...

popen and file operation

related to this question my script basically runs fine but sometimes it stop responding at the fread function call and I can't seem to find the reason of the failure. private function run_lengthy_job($command, $message) { for($handle = popen($command, 'r'); !feof($handle); sleep(2)) { printf("[%s]\t%s\n", time(), $message);...

Portable way to find out if a command exists (C/C++)

C standard library provides functions system and popen to run a command. But is there a portable way to detect if a command exists? ...

Python and subprocess

This is for a script I'm working on. It's supposed to run an .exe file for the loop below. (By the way not sure if it's visible but for el in ('90','52.6223',...) is outside the loop and makes a nested loop with the rest) I'm not sure if the ordering is correct or what not. Also when the .exe file is ran, it spits some stuff out and I ne...