linux 下c/c++ 使用shell命令并加入参数、保存结果

来源:互联网 发布:ubuntu 启动过程 黑屏 编辑:程序博客网 时间:2024/06/05 00:34

                   linux 下c/c++中使用shell命令的格式为: system("ls -l");

  将命令得到结果结果保存的一种方式是: system("ls -l >result.txt");

                 若想使用参数作为传入命令中,使用string:

                                                                string resultTXT = "result.txt";

                                                                string command = "ls -l >" + resultTXT ;

                                                                 system(command.c_str());

0 0
原创粉丝点击