Ozzyberto
Ozzyberto

Reputation: 399

How to run a Windows Forms Application from PHP

I'm trying to run a custom Windows Forms application that accepts command line arguments from a PHP script, but I have not had success so far. This program loads its interactive GUI if no arguments are provided, otherwise it will only process the information and then exit with status 0.

First, I tried using the exec() function and the page would just hang for about two minutes and then the browser would throw a "No data received" error. So I started reading on the exec, popen, proc_open, system, passthru and shell_exec functions. I tried using exec, system and shell_exec to make the program run but to no avail.

Then I found that maybe there was a permissions issue, since the user actually trying to run the program was my web server (Apache/2.2.22 (Win32) PHP/5.3.14) so I accesed the Apache service's properties and had it log on as my own user, restarted the service and managed to get a return value using the exec function.

I also found that in order to prevent the page from hanging I was supposed to set the program to run in the background, however I need to wait for the program's response to let the user know it has finished its work.

The problem right now is that I can only seem to run it without arguments. Which doesn't actually load its GUI, it only returns its status 0, so I'm not sure it actually ran. If I set an argument, then the page hangs and I get a cmd.exe process that won't close itself in the task manager.

PHP Code:

$path = 'start /b "D:/Path/to/program.exe" argument';
$output = array();
$returnVal;
exec($path, $output, $returnVal);

How can I get this program to run?

Update: If I run the program without parameters and appending a > output.txt to the command, I get the following in the output.txt file:

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

D:\WPrograms32\Apache2.2\htdocs>

Upvotes: 3

Views: 2397

Answers (1)

Ozzyberto
Ozzyberto

Reputation: 399

Fixed this problem by converting my project to a Console Application, somehow PHP was able to execute it properly that way.

Upvotes: 2

Related Questions