Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

write to cmd and save output

by Discipulus (Canon)
on Nov 19, 2003 at 12:18 UTC ( [id://308275]=perlquestion: print w/replies, xml ) Need Help??

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

dear monks

I'm in a fix. I run ActivePerl 5.8 on w2k (Sigh).
I need to launch a cmd , send to it some input BUT save all the output of the command to a variable for post processing. I have super-searched a lot and I was not helped so much.

I have tried IPC::Open3 IO::Handle IO::Capture::Stdout without hope..

I need to interact with a well known custom program of my company that run from cmd promp interactively..

any words will be apprecieted for this tipical -- node ;)

cheers from hot sunny roma Lorenzo*

Replies are listed 'Best First'.
Re: write to cmd and save output
by Anonymous Monk on Nov 19, 2003 at 13:55 UTC
Re: write to cmd and save output
by Joost (Canon) on Nov 19, 2003 at 14:02 UTC
    Dunno if this works on win32, but assuming you can do you postprocessing AFTER the command is run:
    open CMD,"|prog.exe >out.log" or die "$!"; print CMD "stuff"; close CMD; open LOG,"<out.log" or die "$!" while (<LOG>) { process($_); } close LOG;
    HTH, Joost
    -- #!/usr/bin/perl -w use strict;$;= ";Jtunsitr pa;ngo;t1h\$e;r. )p.e(r;ls ;h;a;c.k^e;rs ";$_=$;;do{$..=chop}while(chop);$_=$;;eval$.;
Re: write to cmd and save output
by AcidHawk (Vicar) on Nov 19, 2003 at 12:48 UTC

    Update:Doh.. I missed the interactively part..

    If you mean run an executable and capture the output, there are several ways to do this.

    $result = `mycmd.exe -param1 -param2`;

    or you could look at win32::process but you would have to do some clever STDOUT redirection. Some links to follow..

  • Win32 Process Output
  • Re: Capturing error messages from Win32::Process
  • -----
    Of all the things I've lost in my life, its my mind I miss the most.
      expect module is what you want
        except that it's not (it doesn't work on win32)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://308275]
Approved by broquaint
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (5)
As of 2024-04-25 14:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found