Click here to Skip to main content
15,890,973 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I want to write a code to execute the cmd script by c++ , but my code is not working.

What I have tried:

C++
#include "windows.h"

using namespace std;

int main()
{
	
	while (true) {
		WinExec("cmd \"c:\\ahul.cmd\" ",SW_SHOWMINIMIZED);
		Sleep(3000);
	}

	return 0;
}
Posted
Updated 10-Oct-16 0:45am
v2
Comments
Patrice T 10-Oct-16 5:35am    
Define "My code is not working"
[no name] 10-Oct-16 6:18am    
Why are you running the command shell to run a cmd file from the command shell? That makes no sense. Try WinExec("\"c:\\ahul.cmd\" ",SW_SHOWMINIMIZED); and see if it starts working. Then learn how to check the return value from functions to check for errors.

1 solution

You must use the function with the correct parameters.

C++
WinExec("c:\\ahul.cmd",SW_SHOWNORMAL);//cut out unneeded stuff


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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900