I have a batch file and an application developed in Delphi 7. I want to run the batch file with set two parameters on it, when clicking a button. How can I do that?
You can certainly do this with CreateProcess()
as described by @Remy. However, CreateProcess()
is not the easiest of functions to operate. For convenience you may find ShellExecute()
to be a more amenable option:
uses
ShellAPI;
....
ShellExecute(0, 'open', PChar(BatchFileName), 'param1 param2',
nil, SW_SHOWDEFAULT);
Ultimately this will lead to the COMSPEC
variable being read and then a call to CreateProcess()
being made. The advantage is that you let the shell do the heavy lifting for you.
Use CreateProcess()
to run "cmd.exe /C batchfilename parameters"
, where the path to cmd.exe is gotten from the %COMSPEC%
environment variable.