I've written a bash script to take a screenshot and I want to launch it from a PHP page:
#!/bin/bash
screenshot="screnshot.png"
screencapture='/usr/sbin/screencapture -xC'
if [ `whoami` == 'root' ]; then
loginpid=`ps -ax | grep [l]oginwindow.app | awk '{print $1}'`
launchctl bsexec $loginpid $screencapture $screenshot
else
$screencapture $screenshot
fi
When I try to launch it from CLI it works as expected but when I try to launch it with PHP it doesn't work:
<?php
exec("bash /Users/giorgio/Desktop/src.sh");
?>
What's the problem with this?
EDIT:
As you've suggested I've put the script into the PATH eviroment variable (I've edited .bash_profile). Now I can launch the command directly from CLI but the problem launching it from PHP stays the same.
I've tried with those commands but neither of them seems to work:
exec("bash /usr/local/bin/screenshot.sh");
exec("bash screenshot.sh");
exec("screenshot.sh");
EDIT 2:
I've tried to run the following code to indagate on what is happening to the called script:
<?php
$array = array();
$integer;
exec("bash /usr/local/bin/screenshot.sh 2>&1",$array,$integer);
echo "<pre>";
var_dump($integer);
echo "</pre>";
?>
It returns int(133); don't know what it means. P.s. I've also edited the shebang.
EDIT 3:
var_dump of $array returns this:
array(5) {
[0]=>
string(51) "dyld: Symbol not found: __cg_jpeg_resync_to_restart"
[1]=>
string(134) " Referenced from: /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/ImageIO.framework/Versions/A/ImageIO"
[2]=>
string(59) " Expected in: /Applications/MAMP/Library/lib/libJPEG.dylib"
[3]=>
string(0) ""
[4]=>
string(95) "/usr/local/bin/screenshot.sh: line 11: 44948 Trace/BPT trap $screencapture $screenshot"
}
/bin/bash
. Otherwise let us know, how it "doesn't work." – Linus Kleen Feb 14 '12 at 10:43#!
). Editing.bash_profile
is of no use either; it's not used in PHP-cgi. Please make full use ofexec()
diagnostics; examine the code in$return_var
and the script's output. (Output redirection might be necessary; append2>&1
to the command and you should see something in$output
.) – Linus Kleen Feb 14 '12 at 11:25