I want to take two variables from a php script and insert them into a C# program. I have searched online and found a reference to Phalanger(which seems to be a tool to develop php using .Net). It seems like overkill for only needing two variable from my php script. Is there another way to open the a c# application and pass two variables from a php script? Also, can you refer me to a tutorial or post a code example. I have searched the internet, but all I found was references to Phalanger and tools that covert c# code into php.
Asked
Active
Viewed 252 times
1
-
1If your C# stuff is a web app then just do a form post if its a standalone executable you can always use exec() to run the file and pass the arguements in. – Dave Mar 20 '14 at 14:37
-
So I can use $_Post for the variables, how would I connect those to a C# application. The examples online all seem to be between php and html? – Aaron Mar 20 '14 at 14:45
-
you inject your php variables into a html form the user submits and the form posts off the to c# app running on the c# web address etc. or you can use curl within php to send the post vars to the app. of course that only works if its a c# web based app if its a wpf/winforms style app/exe then you need to do as Richard as posted below using the exec command. note this will only work if the php is running on the same server as the c# app – Dave Mar 20 '14 at 15:00
1 Answers
0
I assume you have an executable, which has the normal Program.Main-Entry-Point?
If so, just call exec from php:
$execCommand = printf("app.exe %s %s", $param1, $param2);
exec($execCommand);
[Added part from your comment-question] To use these values anywhere in your application, you can store them in a static class:
public static class PhpValueStore {
public static string Param1 {get; set;}
public static string Param2 {get; set;}
}
Now go to your Main-method which has an "string[] args" as paramter by default. In this method, you can catch the parameters you pasted with your exec-calling. Store the values in the static class:
PhpValueStore.Param1 = args[0];
PhpValueStore.Param2 = args[1];
Cheers!

Richard
- 741
- 2
- 7
- 17
-
I am using a c# windows application, there is not a "string[] args". Should I use "object sender" instead? I have never used a c# windows application before. – Aaron Mar 20 '14 at 15:10
-
No, if you have a object sender, then you're most likely in an event-handler. You should have a Class (and a File) called Programm.cs, which will have a method called Main with the args-parameter. I'll update my answer to show you the easiest way to use the 2 values anywhere in your .net-program. – Richard Mar 20 '14 at 15:29