Getting output from Windows application using PHP
My boss has a Windows app that he wrote. It is not a Windows console application, but a Windows GUI application. We have the source code of course, but he doesn't want this to be a console application. He wants it to remain a regular GUI.
The point is that it wants to be able to call it from PHP, pass its parameters, and return application information to the calling PHP script. I can easily call windows console applications and read the output. I can even call VBS scripts and get output from them.
But we don't understand how to get a normal Windows application to output data to the calling php script without having to write the output to a text file and read it from php.
Anyone could do this? If so, how?
Thanks in advance.
Amy
Edit to add: Apparently the boss put this code in his app:
BOOL bConsole = AllocConsole();
HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
DWORD dwCharsWritten = 0;
string sS3Path = sCommandLine.substr(sCommandLine.find("S3://") + 5);
string sMessage = "S3 Path: " + sS3Path;
BOOL bWritten = WriteConsole(hOutput, sMessage.c_str(), sMessage.size(), &dwCharsWritten, NULL);
But php doesn't see the information it writes to this console. We tried exec and shell_exec to no avail.
a source to share
The best approach is to properly redesign the logic in the Windows GUI application so that it appears as a COM component. A GUI application and PHP script can call a COM component and use the same logic.
In this case, communication is not required and probably should not be via text. You can exchange data by setting and reading the typed properties of a COM component.
This is what COM / is for. And PHP, of course, has a mature library for calling COM components on Windows.
It is really a bad idea to call a GUI application from a web application. You are asking for problems in this. The COM approach is highly preferred.
Update: PHP COM DOC
a source to share
You can pass parameters to the win forms application in the same way as using the command line application. Using the arguments parameter in the main method.
This will require some modification to your winforms application, but it will allow you to call the exe from php by passing some parameters.
I'm not sure what your business requirements are, but ideally, the application is written with a business domain and a split GUI as you most likely don't need this cmd line process to have every winforms application function, but rather produce the proper output from some inputs, it shouldn't be too big to implement the CMD version of the application without rewriting any of your business logic.
a source to share