Article View: borland.public.cppbuilder.nativeapi
Article #10006Controlling another application
From: Bolek
Date: Sat, 29 May 2004 12:33
Date: Sat, 29 May 2004 12:33
35 lines
2158 bytes
2158 bytes
Hello,
I would like to control a command=line app from my program. I tried to
do this by opening a pipe and specifying that pipe as the standard input
handle in CreateProcess = but it does not work. I send my code, too. I
run it on WinXP SP1. How can I make it work? Thanks.
Bolek
----------------------------------------
HANDLE hPipe, hClient;
hPipe = CreateNamedPipe( "\\\\.\\Pipe\\MyPipe", PIPE_ACCESS_DUPLEX,
PIPE_TYPE_MESSAGE | PIPE_WAIT,
PIPE_UNLIMITED_INSTANCES,
1024, 1024, NMPWAIT_USE_DEFAULT_WAIT, NULL);
hClient=CreateFile( "\\\\.\\Pipe\\MyPipe", GENERIC_READ |
GENERIC_WRITE, 0,
NULL, OPEN_EXISTING, 0, 0);
sti.hStdInput = hClient;
sti.hStdOutput = GetStdHandle( STD_OUTPUT_HANDLE);
sti.hStdError = GetStdHandle( STD_ERROR_HANDLE);
CreateProcess( 0, "cmd.exe", 0, 0, TRUE,
NORMAL_PRIORITY_CLASS,
0, 0, &sti, &ps);
char *s = "bla.bat\n";
DWORD d, x;
char buffer[256];
x=WriteFile( hPipe, s, strlen(s), &d, 0);
FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM, 0, x=GetLastError( ), 0,
buffer, sizeof(buffer), 0);
CloseHandle( hClient);
CloseHandle( hPipe);
Technical Details
Message-ID:
<40b882fd@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!controlnews3.google.com!news1.google.com!news.glorb.com!logbridge.uoregon.edu!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,5907943efec0dea8,start X-Google-Attributes: gid10cc67,public Date: Sat, 29 May 2004 14:33:29 +0200 From: Bolek <bolek-konf@eri.cz> User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: borland.public.cppbuilder.nativeapi Subject: Controlling another application Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 83.148.7.163 Message-ID: <40b882fd@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1085833981 83.148.7.163 (29 May 2004 05:33:01 -0700) Lines: 36 Path: arc1-ca.pugleaf.net!controlnews3.google.com!news1.google.com!news.glorb.com!logbridge.uoregon.edu!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail