Running an executable file in PHP
I want to compile a latex file in my PHP code, but it doesn't work. I set the permission of this file to 777. I have the following commands in my code:
$command = '/usr/bin/latex test.tex';
$output = exec($command);
When I try a simple "Hello World!" c++ executable file, it works:
$command = './hello';
$output = exec($command);
Any ide开发者_如何学JAVAa what's wrong?
Di you set the permission of the file test.txt
or the file /usr/bin/latex
? Because /usr/bin/latex
need to be executable by www-data
or whatever you websever is run as.
I would guess that latex depends on environment variables which are not being set properly.
did you try using
exec($command, $output, $retval);
var_dump($output);
in this way you can get the output (if any) of the run.. it may help detect any errors
also, try to use this instead:
pcntl_exec ( string $path [, array $args [, array $envs ]] )
so you can pass arguments and environment values in a more clean way
精彩评论