dexter
dexter

Reputation: 31

Calling another process from python/child process need to access shell

I'm calling a C/C++ program from python with Popen, python code should observe behavior of child process and collect some data for his own work.

Problem is that C code already uses pipes for calling some shell commands - so after my execution from python, C program cannot execute bash shell command.

Is there any way in calling from Popen to specify that, child process should execute his own pipe command in shell???

I tried with shell=True, but doesn't help!

Upvotes: 0

Views: 577

Answers (2)

vy32
vy32

Reputation: 29645

From your description, it seems that you are using Popen to execute a command line, which has Popen call a shell.

You should instead have Popen call your program directly, like this:

from subprocess import Popen,PIPE
p = Popen(['/my/fancy/program','-myarg1','-myarg2'],stdout=PIPE)
from_process = p.communicate()[1]

Upvotes: 2

tesuji
tesuji

Reputation: 56

The best way is probably to use a TCP connection to localhost. If you are using a *nix, you can probably do it by opening a temporary file and polling it from the host application.

Upvotes: 0

Related Questions