-2

I have a c++ program that I call with the following line:

 ./myProgram

However, I'd like to send some external variables to the program (this will eventually be called from PHP via the exec() method). I've searched and read that I should use arguments in the following way:

 ./myProgram <arguments>

However I'm not exactly sure how to use that. Do I separate the arguments by comma if I have more than one, do I need to put type before? And in the C++ file, how do I get these variables?

Can somebody point me to a tutorial for that? Or any other info, code example? Thanks!

4

2 回答 2

2

可执行文件的命令行参数应该用空格分隔。

<?php
    echo exec('myProgram arg1 arg2 arg3');
?>

如果您的参数是数字等......那么您将它们转换为字符串并将该字符串传递给 exec 命令。C/C++ 仅在其主要函数中接受字符串参数。

于 2012-10-24T17:30:34.460 回答
1

您可能需要查看如何使用编译器编译代码

可能这可能会有所帮助: http ://homepages.gac.edu/~mc38/2001J/documentation/g++.html

然后你可以通过调用可执行文件和类似的参数来运行它

./prog 参数

于 2012-10-24T17:33:40.013 回答