PHP系统()args [英] PHP system() args

查看:139
本文介绍了PHP系统()args的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下执行 C ++程式输出的程式码:

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

如何使可以传递参数到c ++程序,像这样...



<$>

如果这是 c ++ p $ p> #include< iostream>
#include< string>
int main(){
string input = getarg(); //真的不是一个函数,只是一个我想知道
cout<输入;
return 0;
}

我可以这样做吗? p>

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

不知道很多零件这个问题, strong>我可以执行程序,但我只是需要传递参数。

解决方案

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



  int main(int argc,char ** argv) {
// argv [1]将指向hello-world
// argv [2] => 2
// argv [3] => 3
}


I have the following code that executes a C++ program and outputs it:

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

How can I make it so that you can pass arguments to the c++ program, say like this...

If this was the c++ program

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

Could I do something like this?

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

I don't know a lot of parts to this problem, I can execute the program but I just need to pass arguments.

解决方案

You can pass the arguments space separated after the command like system("app.exe hello-world 2 3", $out);

in your c++ program

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

这篇关于PHP系统()args的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆