in reply to Capturing error messages from Win32::Process

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.

Replies are listed 'Best First'.
Re: Re: Capturing error messages from Win32::Process
by qadwjoh (Scribe) on Apr 16, 2003 at 12:54 UTC
    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