in reply to Re: call another program from perl
in thread call another program from perl

ouch! I deserve all the criticism, this was probably my worst node. I was reading everything and I couldn't make sens out of it so I wrote something that kind of made sens to me. Anyways, I just started learning Perl so you guys have to give me some credit :) Back to the program, the file.exe opens up like command prompt and in the folder where file.exe is, there is an input file "base.in". So, I need to open file.exe through perl and type in "base" in file.exe for it to take the input file and run. The input file is created by the Perl program. Instead of taking the input file and passing it to file.exe, I'm trying to pass it through the perl program. After running, the program outputs text files into the folder. I would need to read the text file on Perl as well but I guess that's for another time ;).

Replies are listed 'Best First'.
Re^3: call another program from perl
by blazar (Canon) on Jul 19, 2008 at 22:39 UTC
    Back to the program, the file.exe opens up like command prompt and in the folder where file.exe is, there is an input file "base.in". So, I need to open file.exe through perl and type in "base" in file.exe for it to take the input file and run.

    (additional emphasis by me.)

    I personally believe that the info you supplied is unfortunately still incomplete. It is enough to exclude that you have to use system because of that "to type in" - but whether a piped open is appropriate or not depends entirely on the method your file.exe uses to read what you type in. If it reads from STDIN then it's fine, and you only have to read the appropriate documentation linked to above: wrt the naive attempt you shown in the first post the main difference will be a the correct "mode" which is a simple string saying what to do with the filename. (Additionally, you used the two args form of open() in which the mode is attached to the filename itself, and I recommend as usual to use the three args one instead.) Specifically, you used ">" which means "write into" - and that's no good! Perl and the OS "know nothing" about the file itself to the effect that it is actually a program, and "write into" will literally do so, filling its contents with e.g. "base.in"; of course, this is not what you want, thus you have to explicitly tell it that it's a program and that you want to "write to it through STDIN." HTH: filling in the details is left as an easy exercise.

    Incidentally, your original code also had open(-w EXECUTABLE,">$executable") and that looks very incorrect: it is, somewhat surprisingly, syntactically valid due to the existance of the -w function, but that -in turn- is nothing but a test that a given handle is readable, and does not belong there, by any means.

    --
    If you can't understand the incipit, then please check the IPB Campaign.