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

I understand I can pipe a command to a handle like so:
open(NET,"ipconfig /all |");
So, is is possible to do the same to a Win32::API process?
#setup the APi Call $CreateProcess = new Win32::API("kernel32", "CreateProcess",['P','P',' +P','P', 'N','N', 'P','P','P','P'],'N'); $dwFlags 1|0x00000100; my $si = pack("LLLLLLLLLLLL SS LLLL",68,0,0,0,0,0,0,0,0,0,0,$dwFlags,0 +,0,0,-1,-1,-1); my $processinfo = pack("LLLL",0,0,0,0); #now attempt to pipe the call to a handle open(CP,$CreateProcess->Call(0,"ipconfig",0,0,0,0x10,0,".",$si,$proces +sinfo) |);

I am attempting to capture the output of console applications without opening a console window by calling the command through CreateProcess and setting the struct to a hidden window.
I currently get the following error:
The filename, directory name, or volume label syntax is incorrect.

Any help would be appreciated

Replies are listed 'Best First'.
Re: How do I pipe a Win32::API Process to a handle?
by NetWallah (Canon) on Feb 23, 2004 at 18:44 UTC
    Hmmm - no one else seems to want to take this one on, so I'll ask --

    It appears that you trying to re-invent several wheels with redirecting output from processes, and the question is why ?

    Back-ticks work just fine in capturing console output, and do not pop up a console window.

    "Experience is a wonderful thing. It enables you to recognize a mistake when you make it again."

      I'll second that... calling my $results = `ipconfig /all`; would be more than sufficient. Obviously you could also write this to a file

      #!/perl -w use strict; my $results = `ipconfig /all`; open(IPINFO, ">C:/ipconfig.out"); print IPINFO $results; close IPINFO;
      which does produce results formatted exactly the way you would see on the screen. In other words newlines and whitespaces are preserved when receiving output from a backticked command


      Grygonos
      Back-ticks work just fine in capturing console output, and do not pop up a console window.
      If your Perl process is not already associated with a console window, then backticks or open "cmd|" do open a new console window.

      I played around a little trying to get I/O redirection to work using the normal Perl IO constructs and/or POSIX dup2, but it didn't work. I see this Python program to solve the problem. This should be translatable to Perl.

      The only other hint I have is that there is already a Win32::Process module, so you don't have to call CreateProcess using Win32::API.

Re: How do I pipe a Win32::API Process to a handle?
by bart (Canon) on Feb 24, 2004 at 03:05 UTC