in reply to Re^5: Executing command from perl script with input/output
in thread Executing command from perl script with input/output

Thanks Zentara,

I tried the method you suggested above, but this still doesn't work for me :-( After writing the $cmd to WRITE, I created two variables $selread and $selerror (like earlier) - one each to read from READ and ERROR. A read on both of these did not yield anything at all.

I want to use a debugger to see what is happening, but my program is split over several modules, and I am not sure how to use the debugger for something that spans over many modules.

Regards,
ravi

  • Comment on Re^6: Executing command from perl script with input/output

Replies are listed 'Best First'.
Re^7: Executing command from perl script with input/output
by zentara (Cardinal) on Aug 11, 2005 at 10:27 UTC
    Oops, I meant to change the $cmd to "$cmd\n", but I hoped you would figure that out. Remember, the bash shell needs a newline (or enter) to start executing the command. Maybe even use 2 print statements, one to print $cmd, and one to print the code for enter(a newline). Additionally you may need to set $|=1; and maybe even try using syswrite instead of print. If none of those things work, you can try to setup a pseudo-tty, which I find quite difficult. See IO::Pty.

    If all fails you can always fall back to using the old standby "expect" instead of IPC::Open3.

    Quite often, it is some little tiny error you are making which prevents you from getting output, even if you have it setup right, and it usually involves buffering and flushing, so the $|=1 is important. If buffering is the problem, you might see the output as you quit the program.


    I'm not really a human, but I play one on earth. flash japh
      Zentara,

      As expected, I printed the "\n" along with $cmd. However, none of the methods you suggested has worked for me :( I guess I will try installing the Expect module and figure out a way to do this.

      Thanks a lot for your help!