zlatkovic has asked for the wisdom of the Perl Monks concerning the following question:

Hello There, I'm writing a perl module that creates an interface (API) to a command line tool. I'm using the open2 call in order to read and write information to the process. This is working fine on UNIX but when I try it on Windows NT, the open2 call just hangs. I've tried the open2 call just from a perl script and that worked okay. Has anyone else run into this problem and perhaps has a solution? Thanks

Replies are listed 'Best First'.
Re: open2 on Windows NT
by John M. Dlugosz (Monsignor) on May 31, 2001 at 02:03 UTC
    I don't fully understand what you said. Did you mean that some other simple script that called open2 just to make sure it was implemented worked OK, but the specific call in your real program hangs?

    If that's the case, try looking at the actual argument. Does the simple test program open2 the same process with same arguments? If using a string generated at run time, dump that and check for the unexpected. Post a more detailed example.

    —John

      I have written a perl module to interface to a cli ui. Here is a snippet of code from the module
      use IPC::Open2; use Symbol; sub connect_to_cli { my $rdr = gensym(); my $wtr = gensym(); my $pid = open2( $rdr, $wtr, $cmdline ); return $pid; }
      And from a script that uses that module
      use MyModule; my $session = new MyModule(); $pid = $session->connect_to_cli();
      Running the perl script causes things to get stuck on the open2 call. But if I use the open2 call in a perl script it works fine.
      use IPC::Open2; use Symbol; my $rdr = gensym(); my $wtr = gensym(); my $pid = open2( $rdr, $wtr, $cmdline ); print "pid = $pid\n";
      Soraia

      Edit by tye

        Your connect_to_cli is "throwing away" $rdr and $wtr (which should close them) and this may be causing your problems (it certainly makes this subroutinen pretty useless).

                - tye (but my friends call me "Tye")
        Please insert some <CODE> tags around that, and eyeball it in the preview window before submitting—your code is all flowed into a paragraph (see Site How To).

        IAC, print out the value of $cmdline just before making the call to make sure it's as you think it should be.