Article View: borland.public.cppbuilder.nativeapi
Article #15400Redirect
From: Paul Ooi
Date: Fri, 04 Jul 2003 07:52
Date: Fri, 04 Jul 2003 07:52
40 lines
2489 bytes
2489 bytes
Please have a look at the code below, I am trying to redirect the output of
cmd.exe to a TMemo.
HANDLE HNDChildStdoutRd, HNDChildStdoutWr, HNDChildStdinRd,
HNDChildStdinWr;
SECURITY_ATTRIBUTES saAttr;
saAttr.nLength= sizeof(SECURITY_ATTRIBUTES);
saAttr.bInheritHandle = TRUE;
saAttr.lpSecurityDescriptor = NULL;
if (!CreatePipe(&HNDChildStdoutRd, &HNDChildStdoutWr, &saAttr, 0))
PrintError("Stdout pipe creation failed.");
if (!CreatePipe(&HNDChildStdinRd, &HNDChildStdinWr, &saAttr, 0))
PrintError("Stdin pipe creation failed.");
PROCESS_INFORMATION piProcInfo;
STARTUPINFO siStartInfo;
ZeroMemory(&piProcInfo, sizeof(PROCESS_INFORMATION));
ZeroMemory(&siStartInfo, sizeof(STARTUPINFO));
siStartInfo.cb = sizeof(STARTUPINFO);
siStartInfo.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
siStartInfo.wShowWindow = SW_SHOW;
siStartInfo.hStdOutput = HNDChildStdoutWr;
siStartInfo.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
siStartInfo.hStdError = GetStdHandle(STD_ERROR_HANDLE);
if (!CreateProcess("C:\\Windows\\System32\\Cmd.exe", NULL, NULL, NULL,
TRUE, CREATE_NEW_CONSOLE, NULL, NULL, &siStartInfo, &piProcInfo))
PrintError("Process creation failed.");
It works fine but the problem is ReadFile(HNDChildStdoutRd, ......) does not
return when I close cmd.exe, how do I make it return with error when cmd.exe
is closed so that it does not make my program stopped responding ?
Paul
Technical Details
Message-ID:
<3f05324b@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-06!sn-xit-09!sn-xit-08!supernews.com!small1.nntp.aus1.giganews.com!border3.nntp.aus1.giganews.com!border1.nntp.aus1.giganews.com!nntp.giganews.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,309c2f97601c0aca,start X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-07-04 01:07:05 PST From: "Paul Ooi" <yitung.ooi@student.unsw.edu.au> Newsgroups: borland.public.cppbuilder.nativeapi Subject: Redirect Date: Fri, 4 Jul 2003 15:52:43 +0800 Lines: 42 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: 129.94.198.251 Message-ID: <3f05324b@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1057305163 129.94.198.251 (4 Jul 2003 00:52:43 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-06!sn-xit-09!sn-xit-08!supernews.com!small1.nntp.aus1.giganews.com!border3.nntp.aus1.giganews.com!border1.nntp.aus1.giganews.com!nntp.giganews.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail