PHP system() args

I have the following code that executes a <strong>C++ program</strong> and <strong>outputs it</strong>:

<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 <strong>you can pass arguments to the c++ program</strong>, say like this...

If this was the <strong>c++</strong> 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; }

<strong>Could I do something like this?</strong>

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

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

Answer1:

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 }

人吐槽 人点赞

Recommend

Comment

用户名: 密码:
验证码: 匿名发表

你可以使用这些语言

查看评论:PHP system() args