Hazirlamaya calistigim bir programcikta dos satirinda net use komutu ile uzak bir bilgisayara baglaniyor ve baglanti sonucunda oradan bir dosya calistiriyor. Bu baglanti islemi network un durumuna gore 5-10 sn icinde gerceklesebilio. Bu nedenle diger komutu bu baglantiya gore calisirmam icin baglanti sonucunu alana kadar bekletmem gerekiyor. Sleep ile denedim her zaman 10 sn de baglanmiyor ya 15 sn de baglanacagi tutarsa... Bu durumda ikinci komut hata veriyor.
Yukarida aciklamaya calistigim islemi yada external calistirdigim islemlerin sonucuna gore ikinci satiri execute ettirebilmenin yolu nedir acaba...
Yine forum kurallari diyeceksiniz ama viewtopic.php?t=101&highlight=telnet adresinde aradigim yanita benzer birsey buldum. Ama aramalarda yakalamam mumkun olmadi.
function ExecWait(const Cmd: string): Integer;
var
ProcessInfo: TProcessInformation;
hProcess: THandle;
ReturnCode: Integer;
StartupInfo: TStartupInfo;
procedure ChkBool(Value: Boolean; const Msg: string);
begin
if (Value = false) then
raise exception.create(Msg);
end;
begin
FillChar(StartupInfo, SizeOf(StartupInfo), 0);
ChkBool(CreateProcess(nil, PChar(Cmd), nil, nil, False,
CREATE_DEFAULT_ERROR_MODE + NORMAL_PRIORITY_CLASS,
nil, nil, StartupInfo, ProcessInfo),
'Error during CreateProcess');
hProcess := ProcessInfo.hProcess; // save the process handle
//Close the thread handle as soon as it is no longer needed
CloseHandle(ProcessInfo.hThread);
ReturnCode := WaitForSingleObject(hProcess, INFINITE);
ChkBool(dword(ReturnCode) <> WAIT_FAILED, 'Error in WaitForSingleObject');
// The process terminated
ChkBool(GetExitCodeProcess(hProcess, dword(Result)),
'Error in GetExitCodeProcess');
// Close the process handle as soon as it is no longer needed
ChkBool(CloseHandle(hProcess), 'Error in process Close Handle');
end;