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
0
votes
1 answer

Python Popen hanging during second run of script

# @file Test.py # Requirement 1 def requirement1(): ''' Requirement 1: The server will accept command line arguments of: -a / --address -IP address to listen on(default: all or default interface) -p / --port
0
votes
0 answers

curl - suppress stdout header display in C -popen(...) statement

In a Linux C program, I call FILE *fd = popen("curl ipecho.net/plain", "r"); fgets(buffer, BUFFER_CONTENTS_MAX, fd); pclose(fd); to store my machine's IP address into a buffer, and it returns just the IP address (plus some other stuff which I strip…
R. Lambert
  • 11
  • 3
0
votes
1 answer

Why the `stdin` of current progress inflence the behaviour of the command invoked by `popen()`?

As per the manual of popen, which says that[emphasis mine]: The popen() function opens a process by creating a pipe, forking, and invoking the shell. Since a pipe is by definition unidirectional, the type argument may specify only reading or…
John
  • 2,963
  • 11
  • 33
0
votes
0 answers

Read from popen(3) in realtime

Basically, I want to store entire program output in buffers for longer runtimes. Issue is, popen(3) forks a process and since data to be read by poll(2) is delivered in buffered blocks, any intermittent lines between each subsequent call of poll(2)…
lwoivresbo
  • 13
  • 1
  • 4
0
votes
1 answer

Issue with Subprocess Popen Python

I searched on stack overflow but I did'nt find a correct answer. I use subprocess popen to call and run an entire python script and it works fine, like that : subprocess.Popen(['python3', '/home/pc/Dossier/Dossier2/Nom.py'], ) But in my system I…
Mathias
  • 7
  • 3
0
votes
0 answers

Python - Popen doesn't capture stdout completely

So i wanted to capture a whole directory with Subprocess.Popen so i used Stdout=subprocess.PIPE. However when i try to print the directory (which had a lot of files), only half of them showed up. So what i did was: import subprocess data =…
0
votes
2 answers

Opening a File through a Java program using subprocess.Popen() in Python

This is my first ever post on here, and I'm coming here because I've hit a really big roadblock, and after days and days of trying to research possible answers, I've unfortunately come up short. I've also just started to learn how to program about 2…
0
votes
0 answers

Why `setvbuf` does not work with the file stream returned by `popen`?

As per the document, which says that[emphasis mine]: FILE *popen(const char *command, const char *type); Note that output popen() streams are block buffered by default. I hope to see the output of the command executed by popen as soon as…
John
  • 2,963
  • 11
  • 33
0
votes
2 answers

file read/write Popen python

I'm trying to Read/Write process file with command grep and cut to get part of the IP address using pipe operator, here is the process simply written. import subprocess as sub import shlex def discover_Host(): with open("Get_IP.txt",…
user10668235
0
votes
1 answer

Popen() doesn't redirect the stdout to a file

I have a python program that calls a subprocess using Popen(). This python program is called from a C program, using the Python/C API. Everything works fine except for the fact that the subprocess doesn't redirect the output to a file. If I use just…
user17263319
0
votes
1 answer

Run one subprocess after another in a single call that works in the background

To run a subprocess in the background without disturbing the continuity of the main code I call the Python file like this: Popen(['secondary.py'], shell=True, stdin=None, stdout=None, stderr=None, close_fds=True) Is there any way I can use this…
Digital Farmer
  • 1,705
  • 5
  • 17
  • 67
0
votes
0 answers

Why Python Popen stdout missing printf output?

I have a python program running a c++ program as an executable. the c++ program is printing a few prints with std::cout and after it prints a few printing with printf. when I run the program using regular Popen I see all the printing on the output…
0
votes
1 answer

Subprocess.popen() Doesn't Work With Swift

I want to subprocess.popen() a Swift program with Python 3. parent.py: import subprocess #p = subprocess.Popen(['python3', 'sub.py'], universal_newlines = True, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.DEVNULL, bufsize=1) p…
John Hao
  • 3
  • 2
0
votes
2 answers

subprocess and/or Popen doesn't seem to wait for command to complete

I'm issuing the following commands to extract symbol information from an elf file: p = subprocess.Popen(["gdb", "-q", "my.elf", "-ex", symbol, "-ex", "q"], stdin=subprocess.PIPE, stdout=subprocess.PIPE) output =…
KernelSanders
  • 23
  • 1
  • 6
0
votes
0 answers

Running subprocess.Popen in a compiled script has a significant delay

Edit: In this specific example, Python 3.8 is being used on Windows 10. I need to run FFprobe through subprocess.Popen so I can capture and parse the output. If I do this in a script, it runs almost instantly, but if I compile my script with…