how to get into a variable the result of exec() in php


I got an example fortran executable that use two numbers as a parameters and add them and the result is printed in the command prompt

Right now im using a cgi perl script to print the result of the fortran executable in a webpage and it works great, but i would like to know if is it posible to get the result of my program into a variable and echo that variable.

At this moment im trying the following code
$salida = array();
exec("C:\xampp\cgi-bin\prueba6.exe 1000 1000",$salida);
echo $salida[0];

Open in new window

but all the time i got the following error: "Notice: Undefined offset: 0 in C:\xampp\htdocs\prueba1.php on line 5"

What im doing wrong???
Who is Participating?
Brian TaoConnect With a Mentor Senior Business Solutions ConsultantCommented:
I don't think the program is even called and running.  The "\"s (backslashes) need to be escaped, so your line #3 should become:
exec("C:\\xampp\\cgi-bin\\prueba6.exe 1000 1000",$salida);

Open in new window

or just use forward slashes "/"'s and you're fine.
Dave BaldwinFixer of ProblemsCommented:
What do you get if you run the program on the command line?
altariamx2003Author Commented:
it works!!!

thanks a lot
Brian TaoSenior Business Solutions ConsultantCommented:
You're welcome.  Glad to help.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.