Output external program

General discussions related to php

Moderators: egami, macek, gesf

Post Reply
New php-forum User
New php-forum User
Posts: 1
Joined: Fri Jan 12, 2018 5:43 pm

Fri Jan 12, 2018 5:50 pm

Hi there, i'm new and i hope you can help me

I want to know if is possible to get the output of a RUNNING console program, as additional info i use windows 7 if is useful for you


User avatar
php-forum Active User
php-forum Active User
Posts: 365
Joined: Tue Feb 22, 2011 8:19 am
Location: Canada

Fri Mar 16, 2018 4:49 pm


You need to provide more details on exactly what you want to do, why, and what you've tried so far (with code) if you want a useful response.

Step one with troubleshooting queries is always to echo back the full query and run it to see if you get an error.
If you are asking for help with code, please provide the code, the expected result and the actual result, or you will likely not get any replies.

User avatar
New php-forum User
New php-forum User
Posts: 63
Joined: Mon Feb 26, 2018 7:15 am

Fri Mar 16, 2018 9:17 pm

freshnet is right, details are good to have. But I got curious enough to do a quick check and then to also think about the problem. You said a RUNNING program which implies php would not kick off the program.

So...this link does not apply to you because it involves kicking off the program from/by a php script:
Look also at related functions on that page if you can indeed do the execution kick-off from php.

In general, no, if an exe/program is ALREADY running, there is no possible way that I can think of to all of a sudden run some code that can be engaged in direct communication with the running process. There would be no handshake, no line of communication. No direct connection.

But...you could have INDIRECT communication. If the program can be made to generate file-based outputs then you can achieve the desired communication. The php script can be written to consume the files and do whatever is needed based on the file's contents. Even delete the files when done responding. Or update them to reflect some status. A cron job or a script that checks for file-outputs at some interval would be appropriate in this situation.

If the running process has an API for other processes to call it for getting output, you could also create an executable that can be launched by php that would interface with the running program on php script's behalf and return results to php.

On the url page I referenced above, search for the string " Ashraf Kaabi". This guy posted some code that can be used to detect if a process is running, kill it, and then start a new process. This may or may not be feasible in your situation, but it would be one way that php would get a direct handshake with the process and keep it so it would still be running (despite the killing and restarting).

Post Reply