There are those time when it is necessary to execute a batch file from within Delphi. Also in many cases before further processes continue we need to make sure the batch file is finish.
The key to success in this endeavor is to execute a batch file you want to use cmd.exe as the program to execute with the /c Drive:\batfilepath\batfilename.bat parameter options.
sr in the example below contains the value of the ComSpec variable. We use this approach to ensure success execution regardless of system type and system configuration.
sr := GetEnvironmentVariable('ComSpec');
Once the sr variable is populated you can continue to execute the batch file by using the following commands. Of course RExecute and RCommand are both properties with the type of string.
BCSWinExecNWaitdp1.RExecute := sr; BCSWinExecNWaitdp1.RCommand := '/c ' + batpath + '\' + 'batfile.bat'; BCSWinExecNWaitdp1.RExec;
This combination of commands should produce the results you desire.
Mr. Arch Brooks, Software Engineer, Brooks Computing Systems authored this article.