I want to pass MATLAB output to my php code.
My MATLAB code, I have:
function x = returnX()
x = 100;
end
And my PHP code:
<?php
$command = "matlab -nojvm -nodesktop -nodisplay -r \"x = returnX();\"";
passthru($command, $output);
echo($output)
?>
However, this prints 0, not 100.
When I type the command in my cmd, it shows 100. But when I try it through PHP code, it does not work. Can anyone help me how to set the output value of MATLAB to php variable? Thanks!
According to the documentation:
You are
echo
ing the return value from the Matlab command, not standard output. Since the command executed correctly, a 0 is returned.passthru()
will send the content from standard output "without any interference" to the client.Also, make sure your hosting provider allows you to make system calls from within a PHP script. Many hosts disable executing server-side commands for security reasons. Check out the support of safe mode and
disabled_functions
in yourphp.ini
.You should rather use
exec
, which return the standard output, rather than the exit code likepassthru
.display the output in the matlab code:
use
exec
in the php code: