Questions tagged [popen]

popen() is a way to communicate with subprocesses using a file-like interface. It originated in C, but has been ported to other languages (via extensions) such as Python.

FILE *popen(const char *command, const char *type)

popen() (Process OPEN) is a method by which programs can start and communicate with other programs using a file-like interface. This funcion is not mandated by ANSI, but is specified by POSIX.

popen() allows the programmer to avoid the internal workings of fork() and pipe() (this is how it is implemented on UNIX-like systems) by presenting a file object. This allows for the use of functions such as fprintf() and fscanf(), presenting a more orthogonal interface to the programmer (excepting closing the process - the programmer must use pclose() to stop a subprocess).

This function has been ported to a number of programming languages, such as Python (os.popen), Ruby (IO.popen), Tcl (open |command), etc.

2441 questions
9
votes
2 answers

OSError: [Errno 12] Cannot allocate memory from python subprocess.call

I've read several similar posts on this issue but none seem to help me directly. If this actually is a duplicate post, please direct me to the thread containing the solution! I'm saving a bunch of images and then calling ffmpeg on them with…
rhombidodecahedron
  • 7,693
  • 11
  • 58
  • 91
9
votes
2 answers

Python console and text output from Ping including \n\r

I dont know what is happening, but when I am printing to the console or to a text file, the newline (\n) is not functioning but rather showing in the string. Any idea how to avoid this in both the console and the text file? My code: import…
mad5245
  • 394
  • 3
  • 8
  • 20
9
votes
5 answers

How to call popen() with a pathname containing spaces under Windows in C/C++?

I'm trying to call popen() using mingw like this: #define RUN_COMMAND "\"C:\\Program Files\\CA\\BrightStor ARCserve Backup\\ca_qmgr.exe\" \"-list\"" int main() { outputPointer = popen(RUN_COMMAND, "r"); ... } But I can't get it working. I…
GabrieleV
  • 2,303
  • 2
  • 16
  • 9
9
votes
2 answers

Using && in subprocess.Popen for command chaining?

I'm using subprocess.Popen with Python, and I haven't come across an elegant solution for joining commands (i.e. foobar&& bizbang) via Popen. I could do this: p1 = subprocess.Popen(["mmls", "WinXP.E01"], stdout=subprocess.PIPE) result =…
user1260503
9
votes
1 answer

Subprocess.Popen() => No output

I am trying to run a Perl script from within Python, but I get no output in stdout(), while my script perfectly works when I run it from a shell. First, here is how I execute it from shell (assume I am on the right directory): ./vmlinkedclone.pl…
user740316
8
votes
2 answers

How to run Python's subprocess and leave it in background

I have seen A LOT of posts regarding my topic, but actually I didn't find a solution for my problem. I'm trying to run a subprocess in a background, without wait for subprocess execution. The called subprocess is a shell script, which does a lot of…
mchfrnc
  • 5,243
  • 5
  • 19
  • 37
8
votes
2 answers

Get output colored text with Popen

I'm using popen to make a plugin, this plugin used a external program who shows some colored text in the output. The output is something like this: avr-g++ -o .pioenvs\uno\FrameworkArduino\HardwareSerial.o -c -std=gnu++11 -fno-exceptions…
GEPD
  • 198
  • 2
  • 16
8
votes
1 answer

subprocess.Popen() has inconsistent behavior between Eclipse/PyCharm and terminal execution

The problem I'm having is with Eclipse/PyCharm interpreting the results of subprocess's Popen() differently from a standard terminal. All are using python2.6.1 on OSX. Here's a simple example script: import subprocess args = ["/usr/bin/which",…
cybertoast
  • 1,343
  • 13
  • 19
8
votes
7 answers

Can Python open a mp3 file using a separate media player?

Is it possible to open an mp3 file in Python (possible using Popen) and I don't mean to run it in the program I mean as a separate window in media player or whatever just for it to open it when I call the function and if so how?
DonJuma
  • 2,028
  • 13
  • 42
  • 70
8
votes
2 answers

How to determine subprocess.Popen() failed when shell=True

Windows version of Python 2.6.4: Is there any way to determine if subprocess.Popen() fails when using shell=True? Popen() successfully fails when shell=False >>> import subprocess >>> p = subprocess.Popen( 'Nonsense.application', shell=False…
Malcolm
  • 5,125
  • 10
  • 52
  • 75
8
votes
4 answers

Python's Popen cleanup

I wanted to use a python equivalent to piping some shell commands in perl. Something like the python version of open(PIPE, "command |"). I go to the subprocess module and try this: p = subprocess.Popen("zgrep thingiwant largefile", shell=True,…
pythonic metaphor
  • 10,296
  • 18
  • 68
  • 110
8
votes
3 answers

Python's Subprocess.Popen With Shell=True. Wait till it is completed

Submitting a complex cmd string made of a full file path to an executable, the multiple flags, arguments, parameters, inputs and outputs seems to require me to set shell=True otherwise subprocess.Popen is not able understand anything more complex…
alphanumeric
  • 17,967
  • 64
  • 244
  • 392
8
votes
3 answers

FILE * and istream: connect the two?

Suppose I "popen" an executable, I get a FILE* in return. Furthermore, suppose I'd like to "connect" this file to an istream object for easier processing, is there a way to do this?
jldupont
  • 93,734
  • 56
  • 203
  • 318
8
votes
1 answer

Bash style process substitution with Python's Popen

In Bash you can easily redirect the output of a process to a temporary file descriptor and it is all automagically handled by bash like this: $ mydaemon --config-file <(echo "autostart: True \n daemonize: True") or like this: $ wc -l <(ls) 15…
MutantTurkey
  • 536
  • 5
  • 14
8
votes
1 answer

Using Python's subprocess and Popen in one script to run another Python script which requires user interaction (by raw_input)

The problem I have is as follows, and I will use simple example to illustrate it. I have written a python script that requires user interaction, specifically it uses the raw_input() function to get the user's input. The code below simply asks the…
Joshua T
  • 656
  • 8
  • 15