rubble — 2009-06-27T03:30:37-04:00 — #1
I am helpng somebody run a shell script from php and he needs to get the variables created in the script back into the php code when the shell script is finished.
I have suggested he creates the variables in php and send those to the shell script instead; he could do this but would prefer to use the shell script if possible.
This is the code I am using to call the shell script:
$font = "Helvetica-Bold";
$pointsize = "50";
$textcolor = "red";
$undercolor = "blue";
$bordercolor = "yellow";
$angle = "30";
$resize = "100";
// Run the script
exec("/home/user/public_html/fred -f $font -p $pointsize -t $textcolor -u $undercolor -b $bordercolor -a $angle -r $resize fred.png 2>&1", $array);
//Display any errors
old_iron — 2009-06-27T04:35:44-04:00 — #2
Well, exec() returns the last line of the output from the shell command, so if the shell script is returning output like "value" or "a, b, c" you can capture this output in a var or array as needed.
old_iron — 2009-06-27T04:36:36-04:00 — #3
sorry, I just saw you're outputting a png - look into passthru() if you want to output an image to the browser (binary stream).
rubble — 2009-06-27T17:32:13-04:00 — #4
Thats something to think about old_iron and I will do some tests.
I should have put some more info in my post - the image is a CAPTCA image and the characters are generated in the shell script. He needs the characters generated to check against in the form.
The shell script is being written so it can be used by different software.
I have suggested he has the image in the memory only and not save it. The code he has written at the moment has everything hard coded as a test.
I still think the way to go is get php ( or whatever other software ) to generate the random characters and then send them to the shell script.
ernie1 — 2009-06-30T17:41:47-04:00 — #5
how about this
and the php
$cmd = "sh test.sh";
tendolla — 2009-06-30T17:56:10-04:00 — #6
rubble — 2009-07-02T12:28:11-04:00 — #7
Thanks for the replys; I have not tried shell_exec() yet and we are trying to think of another way to solve the problem - lateral thinking !
Ernie1 - I only get one x displayed and that is coming from the shell script; if I comment out echo $re I get nothing displayed.
I would assume I should have xx One x from the shell script and the other from the php code ?
rubble — 2009-07-02T13:06:58-04:00 — #8
I do not get an output from shell_exec() either; I wonder if its a server setup problem.
tendolla — 2009-07-02T14:13:36-04:00 — #9
If you are using some hosting company to host your pages then I think shell_exec and maybe some others also can be forbidden. If you are running own server then it might be some settings also. I dont know more about these settings... I just know some hosting companies disables these.
ernie1 — 2009-07-02T14:23:37-04:00 — #10
you can write to a file then read from that file
echo $re > test
rubble — 2009-07-02T15:34:53-04:00 — #11
That works Ernie1; I end up with a file called test containing x
I will pass on the info and see how it goes