|
-
July 22nd, 1999, 06:31 PM
#1
Executing DOS batch files from C
I am attempting to execute DOS batch files from a C++ program. I tried using the CreateProcess() function but I get no results. The function returns without an error, but the batch file doesn't run.
Any pointers?
-
July 22nd, 1999, 06:34 PM
#2
Re: Executing DOS batch files from C
Hmm.. I use CreateProcess() all the time and I can't conceive of a reason why it wouldn't work for a dos file. Try something simpler like WinExec shown below:
const char cmdLine[] = "\\windows\\notepad.exe";
UINT result = WinExec(cmdLine, SW_SHOW);
if (result < 32)
{
// handle error
}
-
July 22nd, 1999, 07:29 PM
#3
Re: Executing DOS batch files from C
Alrighty.
First, thanks for the first reply. I had found a solution, messy as it is, for my conundrum.
I will try to explain.
To run a .bat file from a windows program, one must use the cmd.exe command from the windows directory. Pass to cmd.exe the name of the batch file you wish to execute as a parameter.
Now be careful not to use DETACHED_PROCESS in the creation flags.
The pain is that it seems you have to change directories to where the batch file lives but use a the full windows path before cmd.exe. (as in C:\WINNT\cmd.exe).
The result is messy because it pops up a DOS window for the execution of the batch.
Be sure to restore the current directory when your done.
-
July 23rd, 1999, 10:10 AM
#4
Re: Executing DOS batch files from C
To Eric
Try this
CreateProcess( NULL, Program, NULL, NULL, FALSE, CREATE_SEPARATE_WOW_VDM | NORMAL_PRIORITY_CLASS, NULL, NULL, &StartUpInfo, &ProcessInfo );
Matthew Cross
-
July 23rd, 1999, 10:16 AM
#5
Re: Executing DOS batch files from C
you can try system();
its very easy to use..
-
July 23rd, 1999, 10:50 AM
#6
Re: Executing DOS batch files from C
you can mess with the CreateProcess options and prevent it from showing a window
miked
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|