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

subprocess.Popen execve() arg 3 contains a non-string value

I'm trying to trying to run another script via the shell, that uses a modified set of environment variables. def cgi_call(script, environ): pSCRIPT = subprocess.Popen(script, stdout=subprocess.PIPE, stderr=subprocess.PIPE, …
Abram I
  • 185
  • 2
  • 7
10
votes
4 answers

poll method of subprocess.popen returning None for long process

I am executing curl command through subprocess. This curl command starts video processing at another server, and waits for the response. Once the process is done, the remote server returns json object. I am checking the status of the subprocess…
Avichal Badaya
  • 3,423
  • 1
  • 21
  • 23
10
votes
6 answers

Popen and python

Working on some code and I'm given the error when running it from the command prompt... NameError: name 'Popen' is not defined but I've imported both import os and import sys. Here's part of the code exepath = os.path.join(EXE File location is…
Tyler
  • 3,919
  • 7
  • 27
  • 26
9
votes
4 answers

C++ popen command without console

when I use popen to get the output of a command, say dir, it will prompt out a console. however, can I get the output of a command without the appearance of the console? I am using Visual C++ and want to make an Library to return the output of some…
user883434
  • 717
  • 2
  • 10
  • 25
9
votes
4 answers

how to concatenate multiple files for stdin of Popen

I'm porting a bash script to python 2.6, and want to replace some code: cat $( ls -tr xyz_`date +%F`_*.log ) | filter args > bzip2 I guess I want something similar to the "Replacing shell pipe line" example at…
Tony Delroy
  • 102,968
  • 15
  • 177
  • 252
9
votes
0 answers

subprocess.Popen hangs for ~70 seconds using Python3?

In my program I have this utility function for executing commands in shell, here's a simplified version of it: def run_command(cmd): s = time.time() print('starting subprocess') proc = subprocess.Popen(cmd.split(), …
9
votes
1 answer

Capture output as a tty in python

I have a executable which requires a tty (as stdin and stderr), and want to be able to test it. I want to input stdin, and capture the output of stdout and stderr, here's an example script: # test.py import sys print("stdin:…
Andy Hayden
  • 359,921
  • 101
  • 625
  • 535
9
votes
3 answers

python - how to pipe the output using popen?

I want to pipe output of my file using popen, how can I do that? test.py: while True: print"hello" a.py : import os os.popen('python test.py') I want to pipe the output using os.popen. how can i do the same?
sami
  • 99
  • 1
  • 1
  • 2
9
votes
4 answers

Tilde (~) isn't working in subprocess.Popen()

When I run in my Ubuntu terminal: sudo dd if=/dev/sda of=~/file bs=8k count=200k; rm -f ~/file it works fine. If I run it through Pythons subprocess.Popen(): output, err = subprocess.Popen(['sudo', 'dd', 'if=/dev/' + disk,…
RichArt
  • 1,534
  • 18
  • 35
9
votes
1 answer

Independent python subprocess from AWS Lambda function

I have successfully created a Lambda function (app1) that reads and writes to RDS. My Lambda function is written in python2.7 and uploaded as a zipped package. I created and tested the zipped package on an EC2 instance in the same VPC as my RDS and…
Lance
  • 638
  • 1
  • 6
  • 22
9
votes
4 answers

How do I close a Python 2.5.2 Popen subprocess once I have the data I need?

I am running the following version of Python: $ /usr/bin/env python --version Python 2.5.2 …
Alex Reynolds
  • 95,983
  • 54
  • 240
  • 345
9
votes
3 answers

LD_PRELOAD affects new child even after unsetenv("LD_PRELOAD")

my code is as follows: preload.c, with the following content: #include #include int __attribute__((constructor)) main_init(void) { printf("Unsetting LD_PRELOAD: %x\n",unsetenv("LD_PRELOAD")); FILE *fp = popen("ls",…
avner
  • 775
  • 1
  • 8
  • 11
9
votes
4 answers

Python 3.4.3 subprocess.Popen get output of command without piping?

I am trying to assign the output of a command to a variable without the command thinking that it is being piped. The reason for this is that the command in question gives unformatted text as output if it is being piped, but it gives color formatted…
nullified
  • 95
  • 1
  • 1
  • 5
9
votes
3 answers

Java: popen()-like function?

This is in the context of a local Processing program. I would like to run an external program to get some data. Is there a popen() or equivalent function I can use?
Mark Harrison
  • 297,451
  • 125
  • 333
  • 465
9
votes
2 answers

Why does supplying stdin to subprocess.Popen cause what is written to stdout to change?

I'm using Python's subprocess.Popen to perform some FTP using the binary client of the host operating system. I can't use ftplib or any other library for various reasons. The behavior of the binary seems to change if I attach a stdin handler to the…
Matt
  • 2,153
  • 1
  • 18
  • 29