从PHP脚本运行c#应用程序

时间:2022-09-02 08:55:18

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.

我想从php脚本中取两个变量并将它们插入到C#程序中。我在网上搜索并找到了对Phalanger的引用(这似乎是使用.Net开发php的工具)。从我的PHP脚本中只需要两个变量似乎有些过分。有没有其他方法可以打开一个c#应用程序并从php脚本传递两个变量?另外,您可以参考我的教程或发布代码示例吗?我在互联网上搜索过,但我发现的所有内容都是对Phalanger的引用以及将c#代码转换为php的工具。

1 个解决方案

#1


0  

I assume you have an executable, which has the normal Program.Main-Entry-Point?

我假设你有一个可执行文件,它具有正常的Program.Main-Entry-Point?

If so, just call exec from php:

如果是这样,只需从php调用exec:

$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:

现在转到你的Main-method,它默认为“string [] args”作为参数。在此方法中,您可以捕获与exec调用粘贴的参数。将值存储在静态类中:

PhpValueStore.Param1 = args[0];
PhpValueStore.Param2 = args[1];

Cheers!

#1


0  

I assume you have an executable, which has the normal Program.Main-Entry-Point?

我假设你有一个可执行文件,它具有正常的Program.Main-Entry-Point?

If so, just call exec from php:

如果是这样,只需从php调用exec:

$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:

现在转到你的Main-method,它默认为“string [] args”作为参数。在此方法中,您可以捕获与exec调用粘贴的参数。将值存储在静态类中:

PhpValueStore.Param1 = args[0];
PhpValueStore.Param2 = args[1];

Cheers!