popen2

Discussion in 'Python' started by g.franzkowiak, Oct 28, 2005.

  1. 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
     
    g.franzkowiak, Oct 28, 2005
    #1
    1. Advertising

  2. g.franzkowiak

    David Wahler Guest

    g.franzkowiak wrote:
    > 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
     
    David Wahler, Oct 28, 2005
    #2
    1. Advertising

  3. David Wahler schrieb:
    > g.franzkowiak wrote:
    >
    >>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
    >


    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
     
    g.franzkowiak, Oct 28, 2005
    #3
  4. On Fri, 28 Oct 2005 22:16:56 +0200, "g.franzkowiak"
    <> declaimed the following in
    comp.lang.python:

    >
    > 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
    --
    > ============================================================== <
    > | Wulfraed Dennis Lee Bieber KD6MOG <
    > | Bestiaria Support Staff <
    > ============================================================== <
    > Home Page: <http://www.dm.net/~wulfraed/> <
    > Overflow Page: <http://wlfraed.home.netcom.com/> <
     
    Dennis Lee Bieber, Oct 29, 2005
    #4
  5. >>>>> "g.franzkowiak" <> (gf) wrote:

    >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.

    --
    Piet van Oostrum <>
    URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4]
    Private email:
     
    Piet van Oostrum, Oct 29, 2005
    #5
  6. On 2005-10-29, Piet van Oostrum <> wrote:
    >>>>>> "g.franzkowiak" <> (gf) wrote:

    >
    >>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.

    --
    Grant Edwards grante Yow! NOW, I'm supposed
    at to SCRAMBLE two, and HOLD
    visi.com th' MAYO!!
     
    Grant Edwards, Oct 29, 2005
    #6
  7. Grant Edwards a écrit :
    > On 2005-10-29, Piet van Oostrum <> wrote:
    >
    >>>>>>>"g.franzkowiak" <> (gf) wrote:

    >>
    >>>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
     
    Pierre Hanser, Oct 29, 2005
    #7
  8. g.franzkowiak

    Donn Cave Guest

    Quoth Pierre Hanser <>:
    | Grant Edwards a écrit :
    |> On 2005-10-29, Piet van Oostrum <> wrote:
    |>>>>>>>"g.franzkowiak" <> (gf) wrote:
    |>>
    |>>>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,
     
    Donn Cave, Oct 29, 2005
    #8
  9. >>>>> Grant Edwards <> (GE) wrote:

    >GE> On 2005-10-29, Piet van Oostrum <> wrote:
    >>>>>>>> "g.franzkowiak" <> (gf) wrote:
    >>>

    >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.


    >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.
    --
    Piet van Oostrum <>
    URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4]
    Private email:
     
    Piet van Oostrum, Oct 29, 2005
    #9
  10. On 2005-10-29, Piet van Oostrum <> wrote:

    >>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.


    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.

    --
    Grant Edwards grante Yow! With YOU, I can be
    at MYSELF... We don't NEED
    visi.com Dan Rather...
     
    Grant Edwards, Oct 29, 2005
    #10
  11. >>>>> Grant Edwards <> (GE) wrote:

    >GE> On 2005-10-29, Piet van Oostrum <> wrote:
    >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.


    >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.
    --
    Piet van Oostrum <>
    URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4]
    Private email:
     
    Piet van Oostrum, Oct 30, 2005
    #11
  12. >>>>> Piet van Oostrum <> (PvO) wrote:

    >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.
    --
    Piet van Oostrum <>
    URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4]
    Private email:
     
    Piet van Oostrum, Oct 30, 2005
    #12
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guy

    popen2

    Guy, Aug 12, 2003, in forum: Python
    Replies:
    1
    Views:
    2,857
    Donn Cave
    Aug 12, 2003
  2. cherico

    popen2 with large input

    cherico, Jan 29, 2004, in forum: Python
    Replies:
    2
    Views:
    333
    Jeff Epler
    Jan 29, 2004
  3. Diez B. Roggisch

    popen2 trouble

    Diez B. Roggisch, Apr 2, 2004, in forum: Python
    Replies:
    2
    Views:
    328
    Diez B. Roggisch
    Apr 5, 2004
  4. A. Lloyd Flanagan

    Possible problem with popen2 module

    A. Lloyd Flanagan, Apr 30, 2004, in forum: Python
    Replies:
    2
    Views:
    323
    A. Lloyd Flanagan
    May 3, 2004
  5. Guest
    Replies:
    1
    Views:
    484
    Donn Cave
    Jun 15, 2004
Loading...

Share This Page