Article View: borland.public.delphi.language.objectpascal
Article #75Re: connecting 2 createprocess - like piping in DOS - how?
From: Bill Mudd
Date: Sun, 25 Jan 2004 22:37
Date: Sun, 25 Jan 2004 22:37
75 lines
3565 bytes
3565 bytes
> > I have 2 console programs that, in DOS, can be "piped" > > one into the other - > > prog1 | prog2 > > > > How can this be done in windows using createprocess > > for each console prog ? > > > > createprocess(prog1, ...) > > createprocess(prog2, ...) > > The redirection is done by the command processor (cmd.exe on NT platforms), so > you could simply execute the commend processor with the same command line you > would use in a DOS box and let it do the work. I recommend using full pathes > for the programs, enclosed in double quotes. > > Procedure ExecuteShellCommand( cmdline: String; hidden: Boolean ); > Const > flags : Array [Boolean] of Integer = (SW_SHOWNORMAL, SW_HIDE); > Var > cmdbuffer: Array [0..1024] of Char; > Begin > GetEnvironmentVariable( 'COMSPEC', cmdBUffer, Sizeof(cmdBuffer)); > StrCat( cmdbuffer, ' /C '); > StrPCopy( StrEnd(cmdbuffer), cmdline ); > WinExec( cmdbuffer, flags[hidden] ); > End; > > Doing it yourself may be possible but would be somewhat cumbersome. You can > specify handles for stdin and stdout for the programs you want to start via > CreateProcess in the STARTUPINFO record. One typically uses a pipe handle for > this. > > > It's connecting the output of progr1 to prog2 that I don't > > understand how to do. It is above my current knowledge but I'm trying to > > learn. If you could provide a simple code example to illustrate the > > explanation it would be appreciated. > > Well, i have never played with that myself, but it may work to open the pipe > for both read and write, attach it to the stdin of program2 and stdout of > program 1, launch both programs and wait for number 2 to finish. > > -- > Peter Below (TeamB) Thanks for the reply Peter. I think I need to learn more before I post this problem. I don't think I know enough to describe it in a way that makes sense. There are several front-ends for these console programs and none of them rely on executing batch files. Most of the GUIs are for Linux but of the 2 obscure ones for Windows/Cygwin, only one makes the source code available. It is in C/C++ and being inexperienced I cannot decipher it very well. But I can tell that they use some kind of stream & buffer combination. The end result is just as fast as doing it from a batch file but with the convenience of having a GUI automate all the commandline switches. I guess I have to break down and get a book on Delphi programming. I'll post this problem again when I know more. Bill Mudd
Technical Details
Message-ID:
<401444fa@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<4013202b@newsgroups.borland.com> <VA.0000a8f7.00216a04@nomail.please>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 109d30,e7804c72082db276 X-Google-Attributes: gid109d30,public X-Google-ArrivalTime: 2004-01-25 14:39:35 PST From: "Bill Mudd" <mcmuddjunkno@earthlink.net> Newsgroups: borland.public.delphi.language.objectpascal References: <4013202b@newsgroups.borland.com> <VA.0000a8f7.00216a04@nomail.please> Subject: Re: connecting 2 createprocess - like piping in DOS - how? Date: Sun, 25 Jan 2004 14:37:06 -0800 Lines: 81 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: 209.86.249.155 Message-ID: <401444fa@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1075070202 209.86.249.155 (25 Jan 2004 14:36:42 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail