Article View: borland.public.delphi.nativeapi
Article #169Problem with CreateProcess
From: Mike Fieger
Date: Mon, 26 Jan 2004 22:20
Date: Mon, 26 Jan 2004 22:20
43 lines
2180 bytes
2180 bytes
Hello!
I need to start a DOS-program and redirect its output to a file from within
a Delphi application.
After some trying I created the following code.
Everything works fine... except for the fact that it stops working as soon
as I try to actually redirect the output to a file... :-(
Can anybody help me with that?
Mike
procedure TForm1.StartDosProg;
var
StartupInfo: TStartupInfo; // for CreateProcess
ProcessInfo: TProcessInformation; // for CreateProcess
begin
// Initialize StartupInfo
FillChar(StartupInfo, SizeOf(TStartupInfo), 0);
StartupInfo.cb := Sizeof(TStartupInfo);
StartupInfo.dwFlags := STARTF_USESHOWWINDOW;
StartupInfo.wShowWindow := SW_SHOWNORMAL;
// Start DOS-prog
if CreateProcess(nil, PChar('fc'), nil, nil, false, NORMAL_PRIORITY_CLASS,
nil, nil, StartupInfo, ProcessInfo) then // this works
//if CreateProcess(nil, PChar('fc >fc.log'), nil, nil, false,
NORMAL_PRIORITY_CLASS, nil, nil, StartupInfo, ProcessInfo) then // this
works not :-( why?
begin
// Program started: Wait till finished...
WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
CloseHandle(ProcessInfo.hProcess);
end
else
begin
// Error starting program
//Application.MessageBox(PChar(sGetErrorString(GetLastError)), 'Error',
MB_OK);
end;
end;
Technical Details
Message-ID:
<401592fe@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f94dd,7d1432a8153d8a6 X-Google-Attributes: gidf94dd,public X-Google-ArrivalTime: 2004-01-26 14:40:05 PST From: "Mike Fieger" <mike.fieger@aon.at> Newsgroups: borland.public.delphi.nativeapi Subject: Problem with CreateProcess Date: Mon, 26 Jan 2004 23:20:55 +0100 Lines: 45 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 NNTP-Posting-Host: 62.47.18.61 Message-ID: <401592fe@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1075155710 62.47.18.61 (26 Jan 2004 14:21:50 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail