[英]passing parameter to running batch file
I have running batch file as my socket listener that will receive data from connected client. 我正在运行批处理文件作为我的套接字侦听器,它将从连接的客户端接收数据。 I want to send command to the connected client through web page, but I am having problem or I have no idea on how to get this work, to pass the parameter to the my running batch file listener.
我想通过网页将命令发送到连接的客户端,但是我有问题,或者我不知道如何进行这项工作,将参数传递给正在运行的批处理文件侦听器。
I tried this code snippet in sending command to client of my running batch file. 我在向正在运行的批处理文件的客户端发送命令时尝试了此代码段。
if(isset($_GET['comparam'])) {
$mycommand = $_GET['comparam'];
foreach ($clients as $send_sock) {
socket_write($send_sock, $mycommand);
}
}
but nothing happens, my code is not working. 但没有任何反应,我的代码无法正常工作。
I appreciate someone can help me on this problem. 我感谢有人可以帮助我解决这个问题。
You are running php from a bacth file so it is PHP CLI. 您正在从bacth文件运行php,因此它是PHP CLI。
$_GET
is for the web version such notion does not exist in Command lines. $_GET
适用于Web版本,这样的概念在命令行中不存在。
The way you would pass argument is like this: 您传递参数的方式是这样的:
C:\some\path\yourScript.php comparam
Then you would read the value from the script like the following: 然后,您将从脚本中读取值,如下所示:
if(isset($argv[1])){
$mycommand = $argv[1];
foreach ($clients as $send_sock) {
socket_write($send_sock, $mycommand);
}
}
$argv — Array of arguments passed to script $ argv —传递给脚本的参数数组
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.