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
8
votes
3 answers

C++ popen()'s output to a string

C++'s popen() returns a file descriptor that contains the output, after executing a process. Instead of a FILE*, I need a char*, ie. a string to be my output. What do I do? Please help me.
Tabrez Ahmed
  • 2,830
  • 6
  • 31
  • 48
7
votes
5 answers

php shell_exec with realtime updating

I have this shell program that I want to execute by php. The problem is that it can potentially take a long time, and as of that I need it to have real-time updating to the user's browser. I read that I may need to use popen() to do that, but I am…
EduAlm
  • 813
  • 3
  • 11
  • 27
7
votes
2 answers

Ruby IO.popen STDOUT buffering

I'm working on a script that uses IO.popen to open another program and continually read the data. It's like this: process = IO.popen(["/the/program", "argument", "argument"]) loop do line = process.gets puts "#{line}" end (The actual program…
Eddie
  • 71
  • 1
  • 2
7
votes
2 answers

popen vs system: is popen as evil as system?

popen buffers output while system does not. is that the only difference? I understand that popen and system both run the command through the shell. However, is popen() as evil as system()?
Ian
  • 3,500
  • 1
  • 24
  • 25
7
votes
1 answer

chaining Popen subprocesses properly

i have a construct like the following: os.mkfifo('pipe.tmp') enc = Popen(['encoder', '-i', 'pipe.tmp']) cap = Popen(['capture', '-f', 'pipe.tmp']) here cap is a process which normally writes to a file (specified by -f), but i can get it to spew…
wim
  • 338,267
  • 99
  • 616
  • 750
7
votes
2 answers

How to achieve desired results when using the subprocees Popen.send_signal(CTRL_C_EVENT) in Windows?

In python 2.7 in windows according to the documentation you can send a CTRL_C_EVENT (Python 2.7 Subprocess Popen.send_signal documentation). However when I tried it I did not receive the expected keyboard interrupt in the subprocess. This is the…
Mario
  • 85
  • 1
  • 2
  • 7
7
votes
3 answers

Capturing terminal output into pandas dataframe without creating external text file

I am using ffmpeg's extract_mvs file to generate some text information. I would use a command like this in the terminal: /extract_mvs input.mp4 > output.txt I would like to use this command with Popen or other subprocess in python such that instead…
tavalendo
  • 857
  • 2
  • 11
  • 30
7
votes
2 answers

popen() writes output of command executed to cout

I am writing an application that needs to open another process and get its output. Everywhere I've read online says I have to use popen and read from the file. But I can't read from it. The output of the command gets outputted into the console…
user2882307
7
votes
2 answers

Popen getting pid of newly run process

I want to run some application in background and later kill it by pid. pipe = IO.popen("firefox 'some_url' 2>&1 &") pipe.pid This code starts firefox and return me some pid, but unfortunately it's not firefox's pid. pipe =…
Sebastian
  • 2,618
  • 3
  • 25
  • 32
7
votes
2 answers

takes 1 positional argument but 2 were given

I would like to run a command line tool to run in a separate function and passed to the button click the additional command for this program but each time I get this as a response. takes 1 positional argument but 2 were given from tkinter import…
MrChaosBude
  • 83
  • 1
  • 1
  • 6
7
votes
1 answer

input to C++ executable python subprocess

I have a C++ executable which has the following lines of code in it /* Do some calculations */ . . for (int i=0; i> inputData; std::cout<<"The data sent from Python is ::…
AdityaG
  • 428
  • 1
  • 3
  • 17
7
votes
3 answers

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…
crystalattice
  • 5,031
  • 12
  • 40
  • 57
7
votes
2 answers

popen fails with "sh: : not found"

I'm developing a server application and I recently encountered this wierd error on a testing server (Debian Squeeze). Every executable I pass to popen fails with a msg: sh: sort: not found // happens to any command This happens regardless whether I…
smallmeans
  • 121
  • 1
  • 6
7
votes
1 answer

Synchronous child process calls for shell scripting (including CLI) in Node.js 0.10.x

Synchronous child process calls are now available in the versions of Node.js that are under development (i.e. unstable). This is great news for writing shell scripts, as it will allow code like this: var history = child_process.execSync('git log', {…
user82216
7
votes
1 answer

C - pipe without using popen

how can I transform this: FILE *f; char in_buffer[80]; f=popen("command","r"); fgets(in_buffer,sizeof(in_buffer),f) without using popen(), but only pipe() or other instruction?
Rick Owens
  • 103
  • 2
  • 5