2

I have a C program which has been compiled to an executable. I can run this program from my console. I am trying to get the output from this program through my web browser so I am using the exec command in PHP. My PHP script works fine when I execute it from the command line, but when I call it over a browser I get no input. Here is my PHP program

    <?php
    echo  exec('/var/www/html/./readcard');
    ?>

The readcard program has 777 permissions. I am guess the issue is something to do with permissions?

1

2 Answers 2

4

You aren't capturing the output. The second argument to exec consists of an array to which the output lines will be placed.

<?php
$output=array();
$rv=0;
exec('/var/www/html/./readcard',$output,$rv);

if($rv!=0)
{
  die("readcard failed, got a return value of $rv\n");
}

foreach($output as $line)
{
  echo("<p>$line</p>\n");
}
?>
Sign up to request clarification or add additional context in comments.

3 Comments

Hi Jack, thanks for that. Still the same. It outputs fine when I execute from the command line though.
I think I have found the problem, my C program is calling a number of share objects and the operating system is preventing this. Trying to change the permissions on these objects.
It could be a path problem - maybe it's not about the permission but the command running through apache just may not be able to see the shared objects
1

You probably just echo the return code of the script, which is zero. You can either redirect the output to a file and then serve that from php, or pipe the output stream directly back to php code.

Try

<?php
    $output = array();
    exec('/var/www/html/./readcard', &$output);
?>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.