Reputation: 21615
I am trying learn to execute shell scripts from within PHP code. So, I made a test program to execute a bash script from within PHP. However, it has no effect. The relevant code is shown below.
<?php
.......
shell_exec('/bin/bash /var/www/html/just_touch.sh');
?>
The just_touch.sh
script just creates a new file, like as shown below.
touch /home/user/some.txt
I was expecting to have file /home/user/some.txt
after execution, but no, it isn't made. What mistake, am I doing?
P.S: The following code works though.
$output = shell_exec('ls /home/user');
echo $output;
Does this have anything to do with permissions?
Moreover, I notice that while this prints "Can you see me?".
$output = shell_exec('echo Can you see me?');
echo $output;
This doesn't!
shell_exec('echo Can you see me?')
What is going on here?
Upvotes: 0
Views: 5720
Reputation: 19727
Stderr is lost when using shell_exec
. You might wan't to use:
shell_exec('/bin/bash /var/www/html/just_touch.sh 2>&1');
Upvotes: 3