2

I have a c# console application that I invoke with a server call in PHP

chdir($filePath);
exec($filePath.$fileName);

This works great, the application is run. The data it is designed to collect is collected and everyone is happy. Currently I have plans on storing the one time use information on a server or a flat file, but then I noticed that while the console application is running and doing it's magic the page hangs waiting for the application to stop. This intrigued me, and now i'm wondering if there is a way for the application to pass it's data back to the page directly?

Note: I'm running Apache2 on Windows 7


Update:

Ended up using

$runCommand = "D:\\ScanBoyConsole\\ScanBoy_Console.exe COM1 9600 8 1 0 1"; 
$WshShell = new COM("WScript.Shell");
$output = $WshShell->Exec($runCommand)->StdOut->ReadAll;
json_decode($output);
2
  • Are you looking for a way in which a c# console application can communicate with the PHP interpreter (without the 'hanging')? If yes, are you perhaps looking for some kind of IPC based solution? Commented Aug 31, 2011 at 13:36
  • The hanging I don't mind. The console application does not take long, however I am designing this for a mobile platform. So maybe? Commented Aug 31, 2011 at 13:40

2 Answers 2

1

If you mean by "directly" that you want the application's output sent to the client while it's still running you might be interested in passthru().
If you're also the author of the C# application you could skip the console application and expose the functionality in a way accessible via php's COM and .Net module.

Sign up to request clarification or add additional context in comments.

Comments

1

The console app should be able to print (using Console.WriteLine), and PHP can take the results of that...

Back in my PHP days, we called scripts all the time (that are nothing but console apps basically) and had the results spit out to the page.

"shell_exec — Execute command via shell and return the complete output as a string"

http://php.net/manual/en/function.shell-exec.php

[So, the only difference is that you should use shell_exec instead of a regular exec]

2 Comments

Can I return php variables? Console.WriteLine("$foo = 'bar';");
I am having troubles with the command. Works when I run it in the cmd prompt . echo shell_exec("cd D:/ScanBoyConsole && D:/ScanBoyConsole/ScanBoy_Console.exe 'COM1' 9600 8 1 0 1"); however the program crashes when I call it like this. I have had this problem before when the CWD was not set.. any thoughts?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.