in reply to Re^2: Process command output after each input
in thread Process command output after each input

Read perldoc IPC::Open3. The 'a' is STDIN to your program, the 'b' is STDOUT, and 'c' is STDERR, (which will be combined into STDOUT if 0 ). So to send a command to $cmd, just " print a 'my_message_to_send' ", where 'a' is the filehandle. That's why it's called IPC Open3 , it opens 3 filehandles to your program.

I'm not really a human, but I play one on earth. flash japh
  • Comment on Re^3: Process command output after each input

Replies are listed 'Best First'.
Re^4: Process command output after each input
by Anonymous Monk on Jan 25, 2005 at 18:11 UTC
    hi
    $cmd = "ci -u file,v"; open3 (a,b,c, $cmd); -- here while unix is executing $cmd it prompts user to enter some message
    but using with open3 its not asking -- looks like "ci" will ask if there is no tty or something.
    I wanted to know if we can still let the underlying command perform its IO as per its doing without open3 (say with "system or exec ($cmd) or `$cmd`"
    Thanks
      It's very hard for me to give answers, when I don't have the code you are using to test with, plus I'm not familiar enough with cvs to know what is supposed to happen.. IPC can be a bit tricky, and sometimes you have to play with it, and see what the files wants. When you run your command, any errors generated by ci, should be on the 'c' filehandle. If you set it to 0, it should be combined into 'b'. Now if you get nothing back on 'b', but you know 'c' is complaining about 'no tty', then maybe there is a bigger problem, like you are trying to run it remotely?

      There is a module called IO::Pty for this, to fool a process into thinking it has a tty.

      There is also the "piped form of open" which you might want to try, instead of IPC::Open3.

      I think you should post another question( with cvs in the title), with the code you have,and what you are actually trying to do. Probably some monk with cvs experience will be able to tell you what to do. You may have to use "expect".


      I'm not really a human, but I play one on earth. flash japh
        Ok,
        Forget RCS/CVS part. Let me rephrase

        $cmd needs some input from user and it will until user enters something. It will first print something on STDOUT and then wait for STDIN. You can imagine like "Press Y or N" and now user has to make choice.
        If I use open3, I am not seeing STDOUT message and program is waiting
        While using "open3" will STDIN of parent be connected to STDIN of child - if not how to achieve this.
        Sample code:
        hello.pl
        #!/usr/intel/bin/perl
        print "Press Y or N:";
        $l = <stdin>;
        print "You have entered $l\n";
        test.pl
        #!/usr/intel/bin/perl
        use IPC::Open2;
        ##can be replaced with open3 later
        #open3 (*HIS_IN, *HIS_OUT, 0, "hello");
        open2 (*OUT, *IN, "hello.pl");
        print <OUT>;
        ## the above should have the same functionality as system --HOW ??
        ##system ("hello.pl");