【问题标题】:PHP system() argsPHP 系统()参数
【发布时间】:2010-09-04 00:32:43
【问题描述】:

我有以下代码执行 C++ 程序输出它

<html>
  <head>
    <title>C++</title>
  </head>
  <body>
    <div><?php 
    system("app.exe", $out);
    echo rtrim($out, "0");
     ?></div>
  </body>
</html>

我怎样才能做到你可以将参数传递给 c++ 程序,像这样说......

如果这是 c++ 程序

#include <iostream>
#include <string>
int main(){
  string input = getarg();//Not really a function, just one I kinda want to know
  cout << input;
  return 0;
}

我可以这样做吗?

<html>
  <head>
    <title>C++</title>
  </head>
  <body>
    <div><?php 
    system("app.exe arg=hello-world", $out);
    echo rtrim($out, "0");
     ?></div>
  </body>
</html>

不知道这个问题的很多部分,我可以执行程序但我只是需要传递参数。

【问题讨论】:

    标签: php c++ system executable exec


    【解决方案1】:

    您可以传递命令后分隔的参数空格,例如 system("app.exe hello-world 2 3", $out);

    在你的 C++ 程序中

     int main (int argc, char** argv) {
        // argv[1] will be pointing to "hello-world"
        // argv[2] => 2
        // argv[3] => 3 
     }
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-04-19
    • 2014-06-06
    • 2011-08-14
    • 2017-08-30
    • 1970-01-01
    • 2014-09-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多