Click here to Skip to main content
15,033,917 members
Please Sign up or sign in to vote.
2.50/5 (3 votes)
See more:
I want to execute .bat file from the cpp code. Can any one suggest me the code to run .bat file from the code in windows 32.
Updated 22-Aug-13 16:08pm
[no name] 22-Aug-13 21:17pm
You did not say for what platform so for Windows,
Sergey Alexandrovich Kryukov 22-Aug-13 22:06pm
As to ".bat file"... Not Windows? Well, not very likely... :-)
Anyway, this link makes a correct answer.
Michael Haephrati 23-Aug-13 18:37pm
It says "Window 32"

There are many ways for starting another executable from a Windows application:

(of course there are few other ways...)
The linked documentation pages provide code examples.
Less than a minute of googling found me this:[^]
You can use ShellExecute[^] if in Windows
I would suggest using ShellExecute.[^]

HINSTANCE ShellExecute(
_In_opt_ HWND hwnd,
_In_opt_ LPCTSTR lpOperation,
_In_ LPCTSTR lpFile,
_In_opt_ LPCTSTR lpParameters,
_In_opt_ LPCTSTR lpDirectory,
_In_ INT nShowCmd

The lpOperation parameter should be "OPEN" and then the lpFile should be the batch file.
I did it myself:
process proc;
proc->workingdirectory="folder path";

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