Y
yonge23
Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TForm1.Button2Click(Sender: TObject);<br>var i:integer;<br> sinfo:TSTARTUPINFO;<br> pinfo:TProcessInformation;<br> ct,et,kt,ut:Tfiletime;<br> hinputfile,houtputfile:THandle;<br> securitySecurityAttributes;<br>begin<br> try<br> //CreatePipe(hReadPipe, hWritePipe, nil, 0);<br> security.nLength:=sizeof(security);<br> security.lpSecurityDescriptor:=NIL;<br> security.bInheritHandle:=TRUE;<br> hInputFile:=CreateFile(pchar('input.txt'),GENERIC_READ,FILE_SHARE_READ,security,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);<br> houtputFile:=CreateFile(pchar('output.txt'),GENERIC_WRITE,FILE_SHARE_WRITE,security,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0);<br><br> FillChar(sInfo,sizeof(sInfo),#0);<br> sInfo.cb := SizeOf(sInfo); // CREATE_NEW_CONSOLE or<br> sinfo.dwFlags:=STARTF_USESTDHANDLES;<br> sinfo.hStdInput:=hInputFile;<br> sinfo.hStdOutput:=houtputFile;<br><br> if not CreateProcess('xxx.exe',nil,nil,nil,false,NORMAL_PRIORITY_CLASS, nil, nil, sInfo, pInfo) then<br> MessageBox(Application.handle,'指定程序启动失败!','错误',MB_OK or MB_ICONSTOP)<br> else<br> begin<br> while (true) do<br> begin<br> sleep(1000);<br> //WaitForSingleObject(pInfo.hProcess,INFINITE);<br> getprocesstimes(pinfo.hProcess,ct,et,kt,ut);<br> if (ut.dwHighDateTime-ut.dwLowDateTime)>1000000000 then<br> begin<br> CloseHandle( pinfo.hProcess );<br> CloseHandle( pinfo.hThread );<br> CloseHandle(houtputFile);<br> CloseHandle(hInputFile);<br> TerminateProcess(pinfo.hProcess,1);<br> ShowMessage(IntToStr(GetLastError));<br> showmessage('运行超时');<br> edit6.Text:=inttostr(kt.dwHighDateTime-kt.dwLowDateTime);<br> exit;<br> end;<br> end;<br> end;<br> except<br> showmessage('测试失败');<br> end;<br>end;<br><br>运行时下面错误:<br>---------------------------<br>Debugger Exception Notification<br>---------------------------<br>Project Project1.exe raised exception class EAccessViolation with message 'Access violation at address 00419C97 in module 'Project1.exe'. Read of address 00000014'. Process stopped. Use Step or Run to continue.<br>---------------------------<br>OK Help <br>---------------------------<br><br>哪位大哥帮忙看看哪位了.可能问题是出现在CREATEFILE处.<br><br>我的程序代码是用来调用外部可执行程序.测试外部可执行程序.测试数据在INPUT.TXT中.测试结果输出到OUTPUT.TXT中.