Running a c# application from a PHP Script

269 views Asked by At

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.

1

There are 1 answers

2
Richard On

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!