views:

240

answers:

4

I have a .exe file. When I run it it asks for the path of a CSV and a .C file. My problem is that I need to execute that .exe through Perl and provide the path of the .C file as well as CSV file path automatically. How can I do that? it is a gui .exe through open command i can browse and give the path of the c file and CSV.I hope it it is clear what am trying to say...

link to snapshot

if u go through this snap shot you can understand my .exe format. i have 2 radio buttons in that and i need select the radio button B and press Run button. if some one gives me an idea how to proceed automatically through perl,hatsoff to them,thanks alot. "IAM USING WINDOWS XP"

+2  A: 

If you just want to execute the application use the system function. As you say you have a .exe I'm assuming Windows so the Perl will look something like:

$exitcode = system("c:\\Path\\App\\bin\\application.exe","C:\\dir\\file.csv");

This is using the recommended way of calling system, passing it an array, with the first entry being the command to run and the other entries being each command line argument. You can pass it a single whitespace separated string but the array method is safer.

If you want to capture the output of the command use backticks. If you are, it's safest to put the file paths in quotes:

$output = `"c:\\Path\\App\\bin\\application.exe" "C:\\dir\\file.csv"`;
print $output;
Dave Webb
+1  A: 

I am guessing you are using Windows. use the System() command to run your code. Here is an example:

system($command, @arguments);

# For example:
system( "sh", "script.sh", "--help" );
system("sh script.sh --help");
Ritesh M Nayak
+1  A: 

The approaches suggested above work fine if the executable is expecting the arguments(inputs) as command line argument. But if your program prompts your for input during its run and expects you to enter the input through standard input, you can try something like this:

Say I have a program named sum.exe which when run prompts me for two numbers and prints their sum.

C:\Documents and Settings> sum.exe
Enter A
1
Enter B
2
1 + 2 = 3

Now to run this sum.exe through perl you can do something like:

system("sum.exe < input");

where the file input has all the inputs that your program expects/prompts during its run. In my case:

C:\Documents and Settings> type input
1
2

So in your case you can make the input file contain the path of CSV file and path of .C file.

codaddict
+4  A: 

With the information you provided, I think you can try IPC-Run or maybe the Expect CPAN module. These allow you to control an external console program from within Perl and pass and read STDOUT/STDERR/STDIN information from it.

Shlomi Fish
Expect doesn't work on Windows.
brian d foy