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

Hi,

my Perl script runs a DOS command line program which doesn't set its exit code correctly, so I'm having trouble determining whether program has failed.

Is there any way I can capture the output of the program even though I've used Win32::Process to launch it?

Thanks,
Andrew
  • Comment on Capturing error messages from Win32::Process

Replies are listed 'Best First'.
Re: Capturing error messages from Win32::Process
by AcidHawk (Vicar) on Apr 16, 2003 at 11:16 UTC

    Look at Win32 Process Output you may have to do some serious STDOUT redirecting stuff though. Here is some code..

    #!perl.exe use Win32::Process; pipe(READ, WRITE); close(WRITE); select(READ); $| = 1; select(STDOUT); open(SAVEIN, "<&STDIN") || die "Can't save STDIN\n"; open(STDOUT, "<&READ") || die "Can't redirect STDOUT\n"; select(STDIN); $| = 1; select(STDOUT); Win32::Process::Create($Process, "c:\\dev\\MiscTests\\Process\\name.exe", "name", 1, NORMAL_PRIORITY_CLASS, ".") or die &Error; chomp($num = "&READ"); open(STDIN, "<&SAVEIN"); close(SAVEIN); close(READ); sleep 5; print "\n\n================================\n"; print "You entered $num\n"; print "About to terminate....\n"; print "End.\n"; sub Error { print Win32::FormatMessage( Win32::GetLastError() ); } open(FILE, "processlog"); chomp( my $var = <FILE> ); close(FILE);
    Name.exe is a helloworld type program that returns a name to STDOUT.

    HTH

    -----
    Of all the things I've lost in my life, its my mind I miss the most.
      Hi HTH,

      I tried your code but can't it to work - I get the output from the program at my DOS prompt but get no output from the Perl script itself.

      What I'm trying to do is automate adding a PGP key to a key-ring using a PGP program, which I suspect doesn't like being automated. I've tried using Expect but it didn't work either.
      I tried the node you are referring to earlier but found it difficult to understand and thus tailor for my situation.

      Any ideas?
      A