简体   繁体   中英

Running a c# application from a PHP Script

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 ac# 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.

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM