Reputation: 423
in dos, i would run the following command
simread31 file.sim
and the program would ask me for 9 inputs.
Now, i'd like to do it in perl. I know i can combine echo
with system
in order for one input, but how to do it for more than one?
many thanks
Upvotes: 0
Views: 120
Reputation: 4104
The reason you're having trouble doing this with system()
is that it's the wrong tool for the job. If you open(my $fh, '|-', 'simread31', 'file.sim')
you'll be able to print
or say
your input to the child program's STDIN.
I'm not at my machine right now so that syntax is from memory. perldoc perlopen
should provide more detail.
Windows
As Windows does not implement the list form of the piped open, you should use something like this:
open(my $fh, '|-', "simread3.exe $sim_file")
Piping input directly from Perl will often be more efficient than opening, writing, closing, piping via system()
, and then cleaning up an external file.
Upvotes: 3