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

I am having great difficulty with trying to run a win32 exe from perl. on the cmd line it would be:
xx.exe word_up
If I try
open(HECK,">xx.exe"); print HECK "word_up";

xx.exe is overwritten with 'word_up'

if I try
open(HECK,"| xx.exe");
I get a crazy win16 bit error, but open(HECK,"| grep up");
works, but that doesn't help me. (grep.exe)
so then I tried ->
use win32; win32::spawn ( "xx.exe", "xx word_up", $Pid );
nothing
Help me out here, please. I am losing.

Thanks

Replies are listed 'Best First'.
Re: win32 pipe help
by etcshadow (Priest) on Aug 12, 2004 at 02:14 UTC
    To put it simply, I think that what you want is one of:
    # run xx.exe word_up and get the output of that program in a variable my $xx_output = `xx.exe word_up`; # just plain run the program... let the output go to the terminal # just as it would be if you ran it at your dos prompt system "xx.exe word_up";
    You're sort of confusing the program's input stream from it's command line. (In perl, this is the difference between STDIN and @ARGV... in C you'd call it stdin and argv/argc... whatever). It's the difference between (again at a command prompt) doing:
    echo stuff | foo.exe
    (where "stuff" is going to be the input to foo.exe) and doing:
    foo.exe stuff
    (where "stuff" is the first parameter to foo.exe). And it's also possible that you're additionally confusing it with:
    foo.exe < stuff
    (where "stuff" is the name of a file, the contents of which are to be the input to foo.exe).
    ------------ :Wq Not an editor command: Wq
Re: win32 pipe help
by ikegami (Patriarch) on Aug 12, 2004 at 02:26 UTC

    It seems you are confusing pipes (sending and/or receving via stdin and stdout of the child program) and command line parameters. open(FH, "| xx.exe"); print FH ("word_up"); would send it to the xx.exe's STDIN, but you mentioned it was a command line argument. You could pass it as an argument by doing open(FH, "| xx.exe word_up");.

    However, I'm not sure if open(FH, "|..."); will do what you want (since I don't know what xx.exe does). Check out the following:

    open(FH, "|...");: Can send command line arguments. Can send commands/data to the child's STDIN, but it's output is not collected. Child operates in parallel with parent.

    open(FH, "...|");: Can send command line arguments. Nothing sent to the child's STDIN, but it's output is collected. Child operates in parallel with parent.

    system(): Can send command line arguments. Nothing sent to to child's STDIN. No output is received from the child. The child exits before the parent continues.

    `` (backticks): Can send command line arguments. Nothing sent to to child's STDIN, but it's output is collected. The child exits before the parent continues.

    Win32::Process (Win32::Spawn is deprecated): Can do anything!