Article View: borland.public.cppbuilder.nativeapi
Article #10028Re: Controlling another application
From: Daniele Borini
Date: Mon, 31 May 2004 11:58
Date: Mon, 31 May 2004 11:58
56 lines
2678 bytes
2678 bytes
Hi,
i tried out Bolek' code, something runs wrong,
this is my code:
if(!CreatePipe(&hRpipe_in,&hWpipe_in,NULL,10000)) return;
if(!CreatePipe(&hRpipe_out,&hWpipe_out,NULL,10000)) return;
memset(&sinfo,0,sizeof(STARTUPINFO));
sinfo.dwFlags = STARTF_USESHOWWINDOW |STARTF_USESTDHANDLES;
sinfo.wShowWindow = SW_NORMAL;
sinfo.hStdInput=hRpipe_out;
sinfo.hStdOutput=hWpipe_in;
sinfo.hStdError=hWpipe_in;
if(CreateProcess(0, "cmd.exe", 0, 0, true,
CREATE_SUSPENDED+NORMAL_PRIORITY_CLASS,
0, 0, &sinfo, &pinfo)){
assert(hRpipe_in);
DWORD i;
char str_out[10000];
strcpy(str_in,"dir *.*\n");
memset(&str_out,0,sizeof(str_out));
int s=strlen(str_in);
WriteFile(hWpipe_out,&str_in,s,&i,NULL);
ResumeThread(pinfo.hThread);
assert(ReadFile(hRpipe_in,&str_out,sizeof(str_out),&i,NULL));
Display->Lines->Add(str_out);
}
i've noticed if i don't use CREATE_SUSPENDED flag process ends
immediatly (i had a look to active processes in task manager).
by creating it suspended i should has the time to write some commands on
the pipe, when i resume the process o think it must execute what i've
specified, but nothing happens and when i try to read from the other
pipe ReadFile blocks program execution, i don't know where the matter is..
Any suggestion?
10X daniele
Remy Lebeau (TeamB) ha scritto:
> "Bolek" <bolek-konf@eri.cz> wrote in message
> news:40b882fd@newsgroups.borland.com...
>
>
>> hPipe = CreateNamedPipe(
>
>
> Use CreatePipe() instead of CreateNamedPipe() and CreateFile().
>
>
> Gambit
>
>
Technical Details
Message-ID:
<40bb1e04@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!controlnews3.google.com!news2.google.com!news1.google.com!news.glorb.com!logbridge.uoregon.edu!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<40b882fd@newsgroups.borland.com> <40b8ec28$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,5907943efec0dea8 X-Google-Attributes: gid10cc67,public Date: Mon, 31 May 2004 13:58:52 +0200 From: Daniele Borini <borini@infinito.it> User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; it-IT; rv:1.6) Gecko/20040113 X-Accept-Language: it, en, en-us MIME-Version: 1.0 Newsgroups: borland.public.cppbuilder.nativeapi Subject: Re: Controlling another application References: <40b882fd@newsgroups.borland.com> <40b8ec28$1@newsgroups.borland.com> In-Reply-To: <40b8ec28$1@newsgroups.borland.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 62.94.67.127 Message-ID: <40bb1e04@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1086004740 62.94.67.127 (31 May 2004 04:59:00 -0700) Lines: 56 Path: arc1-ca.pugleaf.net!controlnews3.google.com!news2.google.com!news1.google.com!news.glorb.com!logbridge.uoregon.edu!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail