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.

2219 questions
0
votes
0 answers

Python subprocess.Popen : how to set a var and read it?

I would like to to create a var with subprocess.Popen and read the content of the var. I don't know how to use subprocess.Popen correctly, I tried : p1 = subprocess.Popen('set var="something"', shell=True, stdin = subprocess.PIPE, stdout =…
Mairkur
  • 125
  • 10
0
votes
1 answer

Is there a way to import a varible from a list made by another python script?

I am pushing a file via FTP to cameras. I want to input ips into my script, which then creates a list, and then opens a new cmd prompt for each ip entered and does the specified commands to successfully push the file to multiple ips at the same time…
0
votes
1 answer

How to detect pclose inside client

How can a C-client started by popen and writing to stdout properly detect that the calling process has called pclose. I am sending binary data from a small client program written in C to Matlab. To this end, Matlab is starting the process by calling…
0
votes
0 answers

Why can my coworker open powershell files through python but I can't?

I have been having a strange issue. For work I am wanting to open a powershell file through python due to various reasons. I have been stuck on how to do this because I have tried everything. Well I have coworker (that works in a much different…
SaturnsBelt
  • 251
  • 2
  • 9
0
votes
1 answer

error status from popen when the command accesses a non existent file

Consider the following 2 lines of code sprintf(comm, "cat %s.bz2 | bunzip2 -dc", string); fp = popen(comm, "r"); If I am opening a file and the file doesn't exist, I will simply get a NULL file. However if I use popen to pipe a file through…
camelccc
  • 2,650
  • 8
  • 24
  • 46
0
votes
1 answer

Popen Executes At the Wrong Time

I am writing a python script and when I run the code, all the code after I run subprocess gets executed before subprocess itself. So for example here the program will run print("blahblafkenrferkfnrnkr") before subprocess. How do I make it so the…
0
votes
1 answer

Python logging strange issue

I have a strange issue where logs are not written to log file. I can't post all the code here, but what I'm doing is the following: I have a logger with file handler and then I execute some script (which I get as input). All the logs that I'm doing…
Morad
  • 2,521
  • 18
  • 25
0
votes
3 answers

Python FileNotFoundError: [Errno 2] despite giving full filepath

So I have written a piece of code which first runs a powershell command to generate a UTF-8 version of a DAT file (have been having special character issues with the original file, hence the step). Following which I try to open the newly created…
0
votes
0 answers

Popen and communicate not working in python

I am using a software for astrophysics spectra called Molly. It is used in the terminal, as a subprocess. I need to execute some commands in that software inside of my python script. So, I am using the subprocess package. I am getting this error and…
Ayo
  • 1
0
votes
1 answer

Kill a subprocess.Popen child with CTRL+c

If I type this command in a terminal, as user root, for say a user bob: su - bob -c "cd /home ; ping www.google.com" It pings continuously until I press CTRL+c. I am trying to mimic a similar behaviour. My setup script runs before I can have…
run_the_race
  • 1,730
  • 17
  • 25
0
votes
2 answers

How to write a subprocess.Popen terminal execution

I want to kill a process on a remote server with another user, who creted the process via python with the subprocess.Popen command. But there is something I must be doing wrong because nothing happens when I…
Varlor
  • 1,161
  • 2
  • 12
  • 34
0
votes
1 answer

C++ Read Continous Command Output stream like tcpdump

I would like to read the continuous output stream of commands like tcpdump from within a c++ program. #include #include #include std::string outputcmd(std::string cmd){ std::string data; char…
abdul rashid
  • 611
  • 7
  • 20
0
votes
1 answer

digital envelope routines:EVP_DecryptFinal_ex:bad decrypt

I'm trying to make a Python program that runs OpenSSL commands for the encryption and decryption of files. In the command line I made: vagrant@vagrant:~$ openssl enc -aes256 -base64 -k $(base64 alice_shared_secret.bin) -e -in plain.txt -out…
PRVS
  • 1,502
  • 4
  • 28
  • 65
0
votes
1 answer

Environment variables not visible in shell script executed using popen in c

Can somebody help on this: I'm executing shell script using popen in c program. Something like this: fd = popen("script1", "r"); script1 code is like this: #!/bin/sh source script2 #loading another script2 EXE_SOMETHING #Function call from…
Dark Matter
  • 300
  • 2
  • 13
0
votes
2 answers

Subprocess pipe breaks program

I am automating a GUI application that also has a CLI. I can successfully run the following (theApplication is an internally developed app): import subprocess process = subprocess.Popen(r'theApplication.exe -foo=7') It then prints its output which…
handras
  • 1,259
  • 9
  • 21
1 2 3
99
100