Article View: borland.public.cppbuilder.nativeapi
Article #10791Capturing output from CreateProcess in WinXP
From: Pete Fraser
Date: Mon, 15 Mar 2004 15:56
Date: Mon, 15 Mar 2004 15:56
36 lines
2239 bytes
2239 bytes
I'm trying to capture the output from an external command but nothing
seems to allow CreateProcess to write it's output to the file I've created.
The string "Fred was here" is always written to the file, but the output
from 'Command' is not.
Does anyone know why and can enlighten me.
Confused, Pete
HANDLE hFile;
STARTUPINFO StartupInfo;
PROCESS_INFORMATION ProcessInfo;
memset(&StartupInfo, 0, sizeof(STARTUPINFO));
StartupInfo.cb = sizeof(STARTUPINFO);
StartupInfo.dwFlags = STARTF_USESHOWWINDOW |STARTF_USESTDHANDLES;
StartupInfo.wShowWindow = SW_SHOW; //SW_HIDE;
hFile = CreateFile("c:\\log.tmp", GENERIC_WRITE|GENERIC_WRITE, 0, NULL,
CREATE_ALWAYS, 0, NULL);
StartupInfo.hStdOutput = hFile;
StartupInfo.hStdError = hFile;
ProcessInfo.hThread = NULL;
ProcessInfo.hProcess = NULL;
if(CreateProcess(NULL, Command.c_str(), NULL, NULL, TRUE,
0, 0, CVSPath->Text.c_str(), &StartupInfo, &ProcessInfo))
{
WaitForSingleObject(ProcessInfo.hProcess, INFINITE); // wait until
command completes
}
else
MessageDlg("Couldn't find command: "+Command, mtWarning,
TMsgDlgButtons() << mbOK, 0);
unsigned long Length = 0;
WriteFile(hFile, "Fred was here", 13, &Length, NULL);
CloseHandle(hFile);
Technical Details
Message-ID:
<4055d230$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.tpinternet.pl!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: 10cc67,c392016e8c59806d,start X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2004-03-15 08:10:19 PST From: "Pete Fraser" <pete._no_spam_fraser@frasersoft.nospam.net> Newsgroups: borland.public.cppbuilder.nativeapi Subject: Capturing output from CreateProcess in WinXP Date: Mon, 15 Mar 2004 15:56:31 -0000 Lines: 38 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: 195.12.18.1 Message-ID: <4055d230$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1079366192 195.12.18.1 (15 Mar 2004 07:56:32 -0800) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.tpinternet.pl!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail