通过C ++ exe运行cmd或bat [英] Run cmd or bat by C++ exe
本文介绍了通过C ++ exe运行cmd或bat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用c ++编写一个代码来执行cmd脚本,但是我的代码不能正常工作。
我尝试了什么:
I want to write a code to execute the cmd script by c++ , but my code is not working.
What I have tried:
#include "windows.h"
using namespace std;
int main()
{
while (true) {
WinExec("cmd \"c:\\ahul.cmd\" ",SW_SHOWMINIMIZED);
Sleep(3000);
}
return 0;
}
推荐答案
您必须使用具有正确参数的函数。
You must use the function with the correct parameters.
WinExec("c:\\ahul.cmd",SW_SHOWNORMAL);//cut out unneeded stuff
通常你不会在C:的根目录中存储一个应用程序,但是在一些ProgramFiles目录中。
我会建议您使用功能更强大的 ShellExecute 因为它的参数更有力量。
Normally you wont store an app in the root of C: but in some ProgramFiles directory.
I would recommand that you use the more powerful ShellExecute because it has more power because of its parameters.
这篇关于通过C ++ exe运行cmd或bat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文