Solved

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

Posted on 2016-10-02
4
56 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

696 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