Daryl Gill
Daryl Gill

Reputation: 5524

Using PHP to pump commands into an already running CMD Prompt

I'm fully aware that PHP has a range of functions available to issue commands to the DOS bck-end of the Windows operating system, alas from my experience. This runs in a completely seperate scenario.

I've been researching into the methodology of issuing commands to an already running command prompt and printing out the results. My current setup is as followed:

Windows Server 2008R2 (IIS, PHP5.5,MSSQL & MySQL server)

an already running command prompt screen initialized by the following:

 C:\Datalog\sys\dedi.exe -logfile=C:\inetpub\wwwroot\Syslog\

The problem now, is that the functions that I'm aware of, such as: exec(), system() and passthru() only run commands in a seperate envrionment.

Why Don't I start the executional with php? This can be done with either PHP and/or with an ajax solution, but the problem that will be encountered is that when navigating away from the page the executional will close & when navigating to page again, it might cause duplicate running environments

So, my overall question.. Is it possible to use PHP to issue commands to an already running command prompt screen? which is kept alive by the operating system?

Upvotes: 1

Views: 73

Answers (1)

Matt S
Matt S

Reputation: 15374

The short answer is no, this is not possible. The web server will launch new processes separate from any other shell. You could write a command line app that runs continuously in a command prompt and takes IPC messages from the web app to get instructions, but this is probably too convoluted given your main concern:

the problem that will be encountered is that when navigating away from the page the executional will close & when navigating to page again, it might cause duplicate running environments

These are concerns that can be resolved in other ways. Processes can be launched asynchronously to run apart from the web application and continue if the connection is closed. To prevent "duplicating the running environment" the launched processes or the web app can use semaphores or other techniques to prevent duplicate runs.

Upvotes: 1

Related Questions