to YB_unique大侠!
谢谢上次您的帮忙,小第改了一下。下面是ping localhost结果保存到b.txt中,但那个localhost
参数还是没能从a.txt中读取。能提示一下吗?我再改改。再次感谢大侠的热心帮忙!
to haoyi,这里很多东西可以删除,你试试吧!
procedure TForm1.Button3Click(Sender: TObject);
var
startupinfo:tstartupinfo;
processinfo:tprocessinformation;
SecAtrrs:TSecurityAttributes;
hInputFile,hOutputFile,hAppThread,hAppProcess:THandle;
mok:boolean;
pcommandline
char;
oldcursor:tcursor;
pstr
char;
pstr2
char;
begin
oldcursor:=screen.Cursor;
screen.Cursor:=crHourGlass;
hinputfile:=0;
houtputfile:=0;
happthread:=0;
happprocess:=0;
if not fileexists('d:/delphi/practice/a.txt') then
hinputfile:=filecreate('d:/delphi/practice/a.txt')
else
hinputfile:=fileopen('d:/delphi/practice/a.txt',fmopenread);
if not fileexists('d:/delphi/practice/b.txt') then
begin
filecreate('d:/delphi/practice/b.txt');
houtputfile:=fileopen('d:/delphi/practice/b.txt',fmopenwrite);
end
else
begin
pstr:=pchar('d:/delphi/practice/b.txt');
pstr2:=pchar('d:/delphi/practice/a.txt');
FillChar(SecAtrrs, SizeOf(SecAtrrs), #0);
; ; SecAtrrs.nLength ; ; ; ; ; ; ;:= SizeOf(SecAtrrs);
; ; SecAtrrs.lpSecurityDescriptor := nil;
; ; SecAtrrs.bInheritHandle ; ; ; := TRUE;
hOutputFile := CreateFile(
; ; ; ;pstr, ; ; ; ; ; ; ; ; ; ; ; ; { pointer to name of the file }
; ; ; ;GENERIC_READ or GENERIC_WRITE, ; ; ; { access (read-write) mode }
; ; ; ;FILE_SHARE_READ or FILE_SHARE_WRITE, { share mode }
; ; ; ;@SecAtrrs, ; ; ; ; ; ; ; ; ; ; ; ; ; { pointer to security attributes }
; ; ; ;CREATE_ALWAYS, ; ; ; ; ; ; ; ; ; ; ; { how to create }
; ; ; ;FILE_ATTRIBUTE_NORMAL
; ; ; ;or FILE_FLAG_WRITE_THROUGH, ; ; ; ; ;{ file attributes }
; ; ; ;0 ); ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; { handle to file with attrs to copy }
; ; // filecr
;hinputfile:=CreateFile(
; ; ; ;pstr2, ; ; ; ; ; ; ; ; ; ; ; ; { pointer to name of the file }
; ; ; ;GENERIC_READ or GENERIC_WRITE, ; ; ; { access (read-write) mode }
; ; ; ;FILE_SHARE_READ or FILE_SHARE_WRITE, { share mode }
; ; ; ;@SecAtrrs, ; ; ; ; ; ; ; ; ; ; ; ; ; { pointer to security attributes }
; ; ; ;CREATE_ALWAYS, ; ; ; ; ; ; ; ; ; ; ; { how to create }
; ; ; ;FILE_ATTRIBUTE_NORMAL
; ; ; ;or FILE_FLAG_WRITE_THROUGH, ; ; ; ; ;{ file attributes }
; ; ; ;0 );
end;
fillchar(startupinfo,sizeof(startupinfo),#0);
startupinfo.cb:=sizeof(startupinfo);
StartupInfo.hStdInput:=GetStdHandle(STD_INPUT_HANDLE);
startupinfo.hStdInput:=hinputfile;
startupinfo.hStdOutput:=houtputfile;
startupinfo.hStdError:=houtputfile;
startupinfo.wShowWindow:=sw_hide;
StartupInfo.dwFlags:=STARTF_USESHOWWINDOW or STARTF_USESTDHANDLES;
pcommandline:='ping localhost';
mok:=createprocess(nil,pcommandline,nil,nil,true,HIGH_PRIORITY_CLASS,nil,nil
,startupinfo,processinfo);
if mok then
begin
WaitforSingleObject(processinfo.hProcess,INFINITE);
hAppProcess:=ProcessInfo.hProcess;
hAppThread:=ProcessInfo.hThread;
end;
closehandle(happprocess);
closehandle(happthread);
closehandle(hinputfile);
closehandle(houtputfile);
screen.Cursor:=oldcursor;
end;