C++中使用调用cmd命令

C++中使用调用cmd命令

方法1:system(“calc”);

方法2: WinExec(“calc”,SW_NORMAL);

System()

1.删除文件/文件夹

string command_rd = "rd /s /q WebCacheV01.dat.export";
system(command_rd.c_str());

2.传入外部参数

system接受完整的外部命令行

system 的命令参数,就组合在字符串中就可以了。 也就是在控制台下的命令, 包括参数, 同时形成一个字符串, 传递给 system 函数即可 ~

因此,如果想要传入外部参数的话,只需要在构造command_string的时候将参数传入,然后将command_string传入system()中就可以了。

string command_esedbexport = "esedbexport -m tables -t WebCacheV01.dat ";
command_esedbexport += edgeBasePath;//这里的edgeBasePath就是外部的可变参数
system(command_esedbexport.c_str());

猜你喜欢

转载自blog.csdn.net/lee_ham/article/details/81778539