🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #15402

Re: Redirect

#15402
From: Paul Ooi
Date: Fri, 04 Jul 2003 10:42
53 lines
2837 bytes
forget i asked, i think i know where i've done wrong.

Paul



"Paul Ooi" <yitung.ooi@student.unsw.edu.au> wrote in message
news:3f05324b@newsgroups.borland.com...
> 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: <3f055a31$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-01!sn-xit-09!supernews.com!news.maxwell.syr.edu!newshosting.com!news-xfer1.atl.newshosting.com!216.166.71.118.MISMATCH!small1.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
References: <3f05324b@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,309c2f97601c0aca
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-07-04 03:58:06 PST
From: "Paul Ooi" <yitung.ooi@student.unsw.edu.au>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <3f05324b@newsgroups.borland.com>
Subject: Re: Redirect
Date: Fri, 4 Jul 2003 18:42:57 +0800
Lines: 55
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: <3f055a31$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1057315377 129.94.198.251 (4 Jul 2003 03:42:57 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-01!sn-xit-09!supernews.com!news.maxwell.syr.edu!newshosting.com!news-xfer1.atl.newshosting.com!216.166.71.118.MISMATCH!small1.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