popen2

G

g.franzkowiak

I start a process in my application with popen2.popen3('MyOtherProcess').
That's ok, but what can I do if the other process is running ?
Can I fetch some information and start with that ?

gerd
 
D

David Wahler

g.franzkowiak said:
I start a process in my application with popen2.popen3('MyOtherProcess').
That's ok, but what can I do if the other process is running ?
Can I fetch some information and start with that ?

gerd

It's not clear what you're asking for. Could you please clarify?

-- David
 
G

g.franzkowiak

David said:
It's not clear what you're asking for. Could you please clarify?

-- David

If starts a process with popen2.popen3('myprogram') and myprogram.exe is
running before, I've a connection to the second process, not to the first.
I can find the process by name before I start a process with popen2...,
but how bcan I connect t this process with a pipe ?

gerd
 
D

Dennis Lee Bieber

If starts a process with popen2.popen3('myprogram') and myprogram.exe is
running before, I've a connection to the second process, not to the first.
I can find the process by name before I start a process with popen2...,
but how bcan I connect t this process with a pipe ?
As I understand it... you Don't...

The OS sets up the pipes as substitutes for stdin/stdout when it
starts the process. The process itself doesn't know if stdin is a file,
some virtual pipe, a keyboard, etc.

Once the process has started, it is accessing stdin/stdout -- you
would have to somehow go inside of the process and change all file
handles/descriptors that were going to stdin/stdout to now go to your
pipe
--
 
P

Piet van Oostrum

g.franzkowiak said:
gf> If starts a process with popen2.popen3('myprogram') and myprogram.exe is
gf> running before, I've a connection to the second process, not to the first.
gf> I can find the process by name before I start a process with popen2...,
gf> but how bcan I connect t this process with a pipe ?

You have to use a named pipe.
 
G

Grant Edwards

You have to use a named pipe.

That would require that the application know about the named
pipe and open it. I don't think there is any way to swap a
pipe in for stdin/stdout once a process is running.
 
P

Pierre Hanser

Grant Edwards a écrit :
That would require that the application know about the named
pipe and open it. I don't think there is any way to swap a
pipe in for stdin/stdout once a process is running.
in C: freopen
 
D

Donn Cave

Quoth Pierre Hanser <[email protected]>:
| Grant Edwards a écrit :
|>>
|>>>gf> If starts a process with popen2.popen3('myprogram') and myprogram.exe is
|>>>gf> running before, I've a connection to the second process, not to the first.
|>>>gf> I can find the process by name before I start a process with popen2...,
|>>>gf> but how bcan I connect t this process with a pipe ?
|>>
|>>You have to use a named pipe.
|>
|>
|> That would require that the application know about the named
|> pipe and open it. I don't think there is any way to swap a
|> pipe in for stdin/stdout once a process is running.
|>
| in C: freopen

Hello, it seems fairly clear that the stdin/stdout in question belongs
to another process, which cannot be instructed at this point to execute
freopen(). If there's a way to do this, it will be peculiar to the
platform and almost certainly not worth the effort.

Donn Cave, (e-mail address removed)
 
P

Piet van Oostrum

Grant Edwards said:
gf> If starts a process with popen2.popen3('myprogram') and myprogram.exe is
gf> running before, I've a connection to the second process, not to the first.
gf> I can find the process by name before I start a process with popen2...,
gf> but how bcan I connect t this process with a pipe ?
GE> That would require that the application know about the named
GE> pipe and open it. I don't think there is any way to swap a
GE> pipe in for stdin/stdout once a process is running.

Sure. 'myprogram' should be designed to communicate through a named pipe,
or be called with named pipe(s) as stdin/stdout.
 
G

Grant Edwards

Sure. 'myprogram' should be designed to communicate through a
named pipe, or be called with named pipe(s) as stdin/stdout.

That's all well and good, but it's got nothing to do with the
OP's problem: he's got a program that's already running and he
wants to write a Python program that can "attach" pipes to that
already running program's stdin/stdout. I know there's no way
to do that under Unix. IIRC, the OP is running Win32, and I'm
not quite as confident that it can't be dont under Win32, but I
don't think it can.
 
P

Piet van Oostrum

Grant Edwards said:
GE> That would require that the application know about the named
GE> pipe and open it. I don't think there is any way to swap a
GE> pipe in for stdin/stdout once a process is running.
GE> That's all well and good, but it's got nothing to do with the
GE> OP's problem: he's got a program that's already running and he
GE> wants to write a Python program that can "attach" pipes to that
GE> already running program's stdin/stdout.

He didn't state that he has no control over that program. I.e. if it is a
program that he has source code of, he could change its behaviour to use a
named pipe.
 
P

Piet van Oostrum

Piet van Oostrum said:
PvO> He didn't state that he has no control over that program. I.e. if it is a
PvO> program that he has source code of, he could change its behaviour to use a
PvO> named pipe.

He could do the initial run of the program with stdin and stdout redirected
to named pipes.At least on Unix that works, I don't know about Windows (but
why not). Later you can write input to the stdin pipe and read the output
back from the other one.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top