1

我想从 php 脚本中获取两个变量并将它们插入到 C# 程序中。我在网上搜索并找到了对 Phalanger 的引用(这似乎是一个使用 .Net 开发 php 的工具)。只需要我的 php 脚本中的两个变量似乎有点矫枉过正。是否有另一种方法可以打开 ac# 应用程序并从 php 脚本传递两个变量?另外,您能否参考我的教程或发布代码示例。我已经搜索了互联网,但我发现的只是对 Phalanger 和将 c# 代码转换为 php 的工具的引用。

4

1 回答 1

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!

于 2014-03-20T14:57:10.013 回答