How to invoke the DOS command from the Delphi program?
1 answer
Options: CreateProcess or ShellExecute. Example (without exception handling):
function RunCommand(command: string; waitable: bool) : bool; var si : TStartupInfo; pi : TProcessInformation; begin ZeroMemory( @si , SizeOf(si)); si.cb := SizeOf(si); Result = CreateProcess(nil, PChar(command), nil, nil, False, 0, nil, nil, si, pi) CloseHandle(pi.hThread); if waitable = true then WaitForSingleObject(pi.hProcess, INFINITE); CloseHandle(pi.hProcess) end;
command is the command line to be executed.
|