Calling PHP Serverside script using shell
When I run client.sh script no output is coming. And when I use "system" command in php the client.sh script is running in infinite loop.
Server.sh: code:
#!/bin/bash
while :
do
printf "Do you want to continue:[Y/N]\n"
read ans
case $ans in
"Y")continue;;
"N")echo "Thank you"
exit 0;;
"*")echo "Wrong choice"
continue;;
esac
done
Output:
srikanth@localhost:~/www/phpshell$ ./scm.sh
Do you want to continue:[Y/N]
Y
Do you want to continue:[Y/N]
N
Thank you
Calls.php: Code:
<?php
$cmd="/home/srikanth/phptest/server.sh";
pcntl_exec($cmd);
?>
Output:
srikanth@localhost:~/phptest$ 开发者_JAVA百科php calls.php
Do you want to continue:[Y/N]
Y
Do you want to continue:[Y/N]
N
Thank you
Client.sh code:
#!/bin/bash
curl http://cxps103/svnadmin/calls.php
Output:
srikanth@localhost:~/phptest$ ./client.sh
Any suggestion would be of much help. Thank you.
Update:
As per Ibu's suggestion am simplifying my question, I had got the problem, there is a while loop in my server.sh
script which causing a problem,
When the CGI script (server.sh
) runs, its standard input is not connected to anything. Therefore the read
command always sets ans
to an empty value, which doesn't match any of the alternatives in the case
statement, and the script loops forever.
As wimvds and others have remarked, your approach is fundamentally wrong. A CGI script generates an HTML page to display in a browser. It acts based on a client request. Once the script has its arguments, it doesn't get input from anywhere (unless it opens files on the server). Interaction for a web application consists of the user entering data in a form and pressing a submit button. Unix interactions such as entering input on stdin and seeing output on stdout don't work over HTTP.
Aside: the "*")
case would only match a line consisting of a single *
character. You probably meant *)
, meaning to match anything.
精彩评论