Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

external program variables

by welle (Beadle)
on Jun 02, 2013 at 19:45 UTC ( #1036616=perlquestion: print w/ replies, xml ) Need Help??
welle has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks

I am not very good in Perl, so maybe my problem is trivial... Which is the best way to transform under Windows the following system() command in a way I can integrate input/output as simple variables?

system ("my_program.exe my_parameter_file.par -option1 -option2 \"inpu +t.txt\" \"output.txt\"" );

I'd like to pass input.txt as a variable and get output.txt as a variable to process it in my script. I have read this but could not come out with a functioning solution. Any advice would be appreciated.

Comment on external program variables
Download Code
Re: external program variables
by Corion (Pope) on Jun 02, 2013 at 19:48 UTC

    I don't think there is a readymade module for that. It still seems to me as if the steps to achieve your goal are simple:

    1. Write input data to file (open, binmode, print, close)
    2. Run program (system, IPC::Run)
    3. Read output (open, binmode, perlop, or File::Slurp)

    Update: The call to close was missing when writing to the input file

      Yes, this is what I am doing now. But, as I have to reiterate this operation an enormous amount of time (the invoked program just do as small operation on a short variable, but I have to do it on 1 million variable->files), I hoped in a better way as writing and reading physical files…

Re: external program variables
by Laurent_R (Vicar) on Jun 02, 2013 at 20:53 UTC

    Not quite sure of what you want, but if you want to read the output of the system command you are issuing, then use the backticks rather than the system function. For example something like this:

    my $output = `some_command.exe $param1 $param2`;

    After that, $output will contain the output of some_command.exe.

Re: external program variables
by Jim (Curate) on Jun 02, 2013 at 21:32 UTC

    So just use variables.

    # Iterate millions of input/output file names... foreach (...) { # Execute external command on pairs of input/output file names... system("my_program.exe my_parameter_file.par -option1 -option2 \ $input_file_name $output_file_name"); }

    Where is the list of millions of input and output file names coming from?

Re: external program variables
by soonix (Deacon) on Jun 03, 2013 at 14:35 UTC
    Hi, welle,
    From your OP, I would assume you want variable file names. If you want to have variable file contents (without the need of disk I/O), the possibility depends on the external program. If it can use STDIN/STDOUT, then you should probably look into IPC::Open2.

      Yes, I ment to pass the content of a variable to the .exe and get the result of the .exe operation in another variable. I'll have a look at what you said.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (7)
As of 2014-08-20 10:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (110 votes), past polls