MATLAB output to PHP code

↘锁芯ラ 提交于 2019-12-08 13:02:51

问题


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!


回答1:


You should rather use exec, which return the standard output, rather than the exit code like passthru.

display the output in the matlab code:

function x = returnX()
    x = 100;
    display(x);
end

use exec in the php code:

<?php
     $command = "matlab -nojvm -nodesktop -nodisplay -r \"x = returnX();\"";
     $output=exec($command);
     echo($output)
?>



回答2:


According to the documentation:

If the return_var argument is present, the return status of the Unix command will be placed here.

You are echoing 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 your php.ini.



来源:https://stackoverflow.com/questions/13106317/matlab-output-to-php-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!