0

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.

Mofi
  • 46,139
  • 17
  • 80
  • 143
jemz
  • 4,987
  • 18
  • 62
  • 102
  • 1
    A batch file itself cannot listen to a socket. If you have a batch file that runs something else and the something else listens to a socket, the batch file is irrelevant. – Jon Aug 06 '14 at 17:20
  • @jon,my batch file is calling my listener.php,this listener is the one who receive the data in socket – jemz Aug 06 '14 at 17:24
  • @jon,what would I do in-order my command will be send to the connected client ? – jemz Aug 06 '14 at 17:26

1 Answers1

1

You are running php from a bacth file so it is PHP CLI.

$_GET is for the web version such notion does not exist in Command lines.

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

meda
  • 45,103
  • 14
  • 92
  • 122
  • thank you for the reply.what is the $argv ?does this refer to comparam? – jemz Aug 07 '14 at 08:36
  • can i ask how do i execute this C:\some\path\mylistener.php comparam ?mylistener.php is the one that's in my batch file – jemz Aug 07 '14 at 09:10
  • you have to put php in front `php C:\some\path\yourScript.php comparam` – meda Aug 10 '14 at 16:07
  • @jemz [How To Run PHP From Windows Command Line](http://stackoverflow.com/questions/15597067/how-to-run-php-from-windows-command-line) – meda Aug 10 '14 at 16:08
  • ,Thank you for the reply but i don't want to manually execute this in cmd,I want to do this dynamically,when i pressed a button in my web it will fires up the cmd to execute the comparam. – jemz Aug 10 '14 at 17:29
  • @jemz this is the question you asked, you put the command in a batch file, and execute the bacth from the website. But this sounds like an overhead since the website is already in php, you can just send a request to this page, and pass it the parameter. if not save this command in a .bat file – meda Aug 10 '14 at 17:36
  • before I can get the value for comparam,I need to pressed the button first in the page and get that value and passed it to comparam variable.then passed the comparam to my listener.php which is always running. – jemz Aug 10 '14 at 17:54
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/59056/discussion-between-meda-and-jemz). – meda Aug 10 '14 at 17:55