0

Is this possible?

What I want to do is send:

run_app.exe -param 'test' -name 'tester'

to a windows cmd line from PHP.

Is this possible or do I need to write a windows service that is somehow triggered by the application?

kieran
  • 2,304
  • 4
  • 28
  • 44

4 Answers4

1

Have you tried exec?

erenon
  • 18,838
  • 2
  • 61
  • 93
1

You can use exec() for that.

madkris24
  • 483
  • 1
  • 4
  • 16
0

Here is a project that allows PHP to obtain and interact dynamically with a real cmd terminal. Get it here: https://github.com/merlinthemagic/MTS

After downloading you would simply use the following code:

//if you prefer Powershell, replace 'cmd' with 'powershell'
$shellObj    = \MTS\Factories::getDevices()->getLocalHost()->getShell('cmd');

$strCmd1   = 'run_app.exe -param "test" -name "tester"';
$return1   = $shellObj->exeCmd($strCmd1);

The return will give you the command return OR error from cmd, just as if you sat at the console. Furthermore, you can issue any command you like against the $shellObj, the environment is maintained throughout the life of the PHP script. So instead of bundling commands in a script file, just issue them one by one using the exeCmd() method, that way you can also handle the return and any exceptions.

MerlinTheMagic
  • 575
  • 5
  • 16
0

Or you can use:

$WshShell = new COM("WScript.Shell");
$oExec = $WshShell->Run(strCommand, [intWindowStyle], [bWaitOnReturn]);

Here you can find the run method params: http://msdn.microsoft.com/en-us/library/d5fk67ky%28v=vs.85%29.aspx

And here is the COM class doc: http://www.php.net/manual/en/class.com.php

With this method you can do so much more in windows :). I used it becaus of the [bWaitOnReturn] parameter which I couldn't do using any other method.

Catalin
  • 858
  • 5
  • 16