0

I can't get output from executable file (a.out) via php. my php code is :

$file = "/path/main.cpp";
$command="cd $path && c++ -lm ".$file;
exec($command);
$output = exec("cd $path && ./a.out");
exec("cd $path && ./a.out > res.txt");
var_dump($output);

all commands is executed but, I'm getting empty value;

exec("cd $path && ./a.out > res.txt");

this command also executed, res.txt was created in folder, but empty file. How to solve this problem? My OS is CentOS 7

Andrei
  • 3,434
  • 5
  • 21
  • 44

1 Answers1

0

In order to get the output of a command with PHP, you can use the shell_exec function:

shell_exec

shell_exec — Execute command via shell and return the complete output as a string

So, try this:

$output = shell_exec("cd $path && ./a.out");
user2342558
  • 5,567
  • 5
  • 33
  • 54