Solved

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

Posted on 2016-10-02
4
50 Views
Last Modified: 2016-10-03
Hi

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
<?php
$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???
0
Comment
Question by:altariamx2003
  • 2
4 Comments
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 41825709
What do you get if you run the program on the command line?
0
 
LVL 9

Accepted Solution

by:
Brian Tao earned 500 total points
ID: 41825870
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.
0
 

Author Closing Comment

by:altariamx2003
ID: 41826345
it works!!!

thanks a lot
1
 
LVL 9

Expert Comment

by:Brian Tao
ID: 41826573
You're welcome.  Glad to help.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
$_SERVER Variable question 31 56
Reference key in foreach loop 4 40
PHP 7 issue seeing runtime MS SQL driver in PHP info page 5 37
Change a button after e-mail 4 22
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question