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

How to Pass multiple arguments with values to executable via Python3?

I am trying to run a windows executable via python3 and have below code snippet. The arguments can be of the form key-value pair but its possible that few arguments may not have value like arg1 below. arg2 needs to have a value which is passed as…
Helena
  • 444
  • 2
  • 15
0
votes
1 answer

Calling parent instance thru child in subprocess python

I have a file parent.py that calls its child called child.py using subprocess. Similar to this: p = subprocess.Popen(["C:/Users/.../child.py", some_arg1, some_arg2],shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE,…
Gordian
  • 101
  • 8
0
votes
0 answers

Popen in multiprocessing.Pool is extremely slow

I'm trying to run multiple ngspice simulation in parallel. So I have a function _runNgspice that executes ngspice. import pandas as pd from subprocess import PIPE, Popen from multiprocessing import Pool def _runNgspice(param): …
user1380653
  • 53
  • 1
  • 4
0
votes
1 answer

Is it possible to pass popen() a string and have it return null?

While working on line/branch coverage for a unit test, I came across the following code bool run_command(char *command) { FILE *handle = popen(command, "r"); if (handle == nullptr) { std::cerr << "" << std::endl; return…
Epsilon
  • 1,016
  • 1
  • 6
  • 15
0
votes
0 answers

I am facing issue while using subprocess.Popen in Popen

My requirement is, I am calling a shell script from my python script. When the python script is executed. It shows all the shell script content(not only the echo, even the secret keys which are read from param files in shell script) in the…
Reddy
  • 7
  • 2
0
votes
1 answer

Execute .exe file and interact with it

I have a executable file (.exe) that performs 3 different actions. Once in its main screen, the user can type '1', '2' or '3', to select which action the .exe must perform. Now, as many of these actions are performed repeatedly, I am trying to…
JohnCalms
  • 87
  • 7
0
votes
1 answer

Does popen load whole output into memory or save in a tmp file(in disk)?

I want to read part of a very very large compressed file(119.2 GiB if decompressed) with this piece of code. FILE* trace_file; char gunzip_command[1000]; sprintf(gunzip_command, "gunzip -c %s", argv[i]); // argv[i]: file path trace_file =…
Tokubara
  • 392
  • 3
  • 13
0
votes
1 answer

Popen stdout value

im doing a ctf challenge about an SSTI. The solution payload is {{"".__class__.__mro__[1].__subclasses__()[213](['cat','flag.txt'],stdout=-1).communicate()}} I would like to know why stdout accepts -1 as a value. I could not find it in the current…
João Luca
  • 5
  • 1
  • 1
0
votes
1 answer

Python. Continuous io eschange with subprocess.Popen() child process

I made a simple model of what I am doing in a bigger application. I am trying to figure out how to communicate with the Popen process so that it is going to wait for io when required, and the user could provide that input. How to do it and is it…
Andrey Kachow
  • 936
  • 7
  • 22
0
votes
3 answers

Running scripts whose purpose is to change shell variables with subprocess.popen

I have a series of scripts I am automating the calling of in python with subprocess.Popen. Basically, I call script A, then script B, then script C and so forth. Script A sets a bunch of local shell variables, with commands such as set…
Chris
  • 757
  • 1
  • 5
  • 6
0
votes
0 answers

C++ popen calls start failing after some time

I have a C++ application that periodically calls the following function in order to run a shell command and return the output: string run_shell_command(const string& command) { array buffer; string response; FILE* pipe =…
galpo
  • 183
  • 1
  • 7
0
votes
0 answers

How to get the PID of the running service in the new window with python?

I want to create a window through CMD / K start, start the jar package in this new window and get the PID of the jar package.I've tried some methods, but none of them can. pid = Popen(['cmd', '/k', 'start', 'java', '-jar',…
0
votes
1 answer

How do you use a python variable in popen()?

Im trying to record docker stats for every file in the mydata directory. For example if one of the files is names piano.txt I would like the output file to be piano_stuff.txt. This is what I have so far: import subprocess import signal import os…
cat
  • 1
  • 1
0
votes
0 answers

why is popen inside chroot is not working in C++ program

I am trying to use basic linux command "ls" inside chroot,I have required library for ls is present in the folder,i could acess ls manually,but not able to use vi cpp program. Find the below program #include #include #include…
0
votes
0 answers

which python function to use to run bash script on remote server? subprocess.Popen, call? new to python

I am running on python 2.7.5. I am converting some bash script to python (learning as I coding) and I'm confused on which is the better solution? I need to copy files to a remote server and then run a script on that remote server using the file. I…
1 2 3
99
100