Witam,
w jaki sposób z poziomu delphi przekazać do pliku *.bat parametry i wykonać go?
próbowałem na kilka sposobów i żaden nie daje pożądanego rezultatu:
- WinExec()
WinExec('c:\sciezka\plik.bat parametr1 parametr2',SW_SHOW);
- ShellExecuteEx()
function uruchom(nazwaPliku:string; parametr1: string; parametr2: string):cardinal;
var
Rec: TShellExecuteInfo;
return: cardinal;
begin
FillChar(Rec, SizeOf(Rec), #0);
Rec.cbSize := SizeOf(Rec);
Rec.fMask := SEE_MASK_NOCLOSEPROCESS;
Rec.lpVerb := PChar('');
Rec.lpFile := PChar(nazwaPliku);
Rec.lpParameters := PChar( parametr1 + ' ' + parametr2);
Rec.lpDirectory := PChar('');
Rec.nShow := SW_SHOW;
ShellExecuteEx(@Rec);
hProcess := Rec.hProcess;
if Rec.hProcess<>0 then begin
WaitForInputIdle(Rec.hProcess, 5000);
GetExitCodeProcess(Rec.hProcess, return);
Result := return;
CloseHandle(Rec.hProcess);
end;
end;
- createProcess()
function uruchom2(nazwaPliku: string; parametr1: string; parametr2: string): Boolean;
var
StartupInfo: TStartupInfo;
ProcessInfo: TProcessInformation;
return : cardinal;
begin
result := true;
FillChar(StartupInfo, SizeOf(TStartupInfo), 0);
StartupInfo.cb := SizeOf(TStartupInfo);
StartupInfo.dwFlags := STARTF_USESHOWWINDOW;
StartupInfo.wShowWindow := SW_SHOW;
CreateProcess(PChar(aFileName), PChar(' '+parametr1+ ' ' + parametr2), nil,nil, False, NORMAL_PRIORITY_CLASS, nil, nil,StartupInfo, ProcessInfo);
GetExitCodeProcess(ProcessInfo.hProcess, return);
while return = STILL_ACTIVE do begin
Application.ProcessMessages;
result := GetExitCodeProcess(ProcessInfo.hProcess, return);
end;
end;
pozdrawiam Dawid