简体   繁体   中英

PHP shell_exec not working

I'm trying to run a shell script on my MacOSX, but it's not working. My report.sh file calls another .sh file (Sweave.sh) that is stored in /usr/local/bin.

<?php

shell_exec("./report.sh");
echo "Hello 123";

?>

It print's 'Hello 123' on my browser, but report.sh is not doing it's job. Why that happens? Here's report.sh:

# !/bin/bash
Sweave.sh -ld test_sweave.Rnw

If if call ./report.sh from the terminal, it works ok...thanks for any help!

EDIT: If i call ./report.php from the terminal, it says:

./report.php: line 2: ?php: No such file or directory
./report.php: line 4: syntax error near unexpected token `"./report.sh"'
./report.php: line 4: `shell_exec("./report.sh");'

If you want to run your script via command line you have to either:

a) start the file with this line

#!/path/to/php

b) run as:

php report.php

If that works, it could be due to permissions, since your web server runs under a different user than you.

Thanks everyone for the comments, it was a permission issue. I solved it by changing permissions for the 'Documents' folder of my server (i'm sure it's not the safest way, but i`m just testing anyway).

Just add rw access, be the owner and apply to enclosed items - thats it!

php -q report.php可以在没有shebang的情况下工作( #!/path/to/php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM