delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2004/10/28/03:03:15

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Subject: Re: pipe data form windows program to cygwin program
From: bertrand marquis <bertrand DOT marquis AT sysgo DOT com>
To: Bob Byrnes <byrnes AT curl DOT com>
Cc: cygwin <cygwin AT cygwin DOT com>
In-Reply-To: <20041027193737.BAA5AE55A@wildcard.curl.com>
References: <20041027193737 DOT BAA5AE55A AT wildcard DOT curl DOT com>
Organization: SYSGO AG
Message-Id: <1098947023.4204.6.camel@bma.sysgo.com>
Mime-Version: 1.0
Date: 28 Oct 2004 09:03:43 +0200
X-Spam-Checker-Version: SpamAssassin 2.63 (2004-01-11) on donald.sysgo.com
X-Spam-Level:
X-Spam-Status: No, hits=-4.9 required=5.0 tests=BAYES_00 autolearn=no version=2.63
X-AntiVirus: checked by AntiVir MailGate (version: 2.0.1.16; AVE: 6.28.0.12; VDF: 6.28.0.42; host: mailgate.sysgo.de)

--=-JhUJolMo8hJIa2nNeGDX
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

hi again,

i join to this mail an example. This must be compiled with mingw
compiler.

the program is going great but at the end gzip( or you can try with cat
to see that data is in output file) stay open.

bertrand



Le mer 27/10/2004 =C3=A0 21:37, Bob Byrnes a =C3=A9crit :
> > I'm writing a program which need to send data to a cygwin program using
> > a pipe on the stdin (actually data to compress using gzip).
> >=20
> > All is working well but at the end of the program when i close the pipe
> > it seems that gzip doesn't see that the pipe has been closed and so it
> > stay open.
>=20
> Are you *sure* that you have closed *all* of the write handles to the pip=
e?
> If any write handles remain open, then EOF won't be delivered to the
> read side of the pipe.
>=20
> > I kind of think there must be something with windows<->cygwin EOF but i
> > can't find out what.
> >=20
> > Is anyone has an idea ?
>=20
> If you can provide a (very) simple test case that exhibits allegedly
> incorrect behavior, that would be helpful.
>=20
> --
> Bob
>=20
> --
> Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
> Problem reports:       http://cygwin.com/problems.html
> Documentation:         http://cygwin.com/docs.html
> FAQ:                   http://cygwin.com/faq/
>=20

--=-JhUJolMo8hJIa2nNeGDX
Content-Disposition: attachment; filename=winpipe.c
Content-Type: text/x-c; name=winpipe.c; charset=UTF-8
Content-Transfer-Encoding: 7bit

#include <stdio.h>
#include <windows.h>
#include <fcntl.h>
#include <process.h>

main()
{

	HANDLE newstdout,newstdin,parent,handles[2];
	int phandles[2],compressor_pid,archivefd;
	
	/*open a file to put data on*/
	
	archivefd = open("test.gz", O_WRONLY | O_TRUNC | O_CREAT | O_BINARY,0666 & ~umask(0));
	
	/*save current handles*/
	parent=GetCurrentProcess ();
	handles[0] = GetStdHandle (STD_INPUT_HANDLE);
	handles[1] = GetStdHandle (STD_OUTPUT_HANDLE);
	
	/*create a new pipe*/
	_pipe(phandles,0,O_BINARY);
	
	/*set pipe of stdin of process form our stdout*/
	DuplicateHandle (parent,
		       (HANDLE) _get_osfhandle (archivefd),
		       parent,
		       &newstdout,
		       0,
		       TRUE,
		       DUPLICATE_SAME_ACCESS);
	
	/*set pipe of stdout of process to open file*/
	DuplicateHandle (parent,
	       (HANDLE) _get_osfhandle (phandles[0]),
	       parent,
	       &newstdin,
	       0,
	       TRUE,
	       DUPLICATE_SAME_ACCESS);
	
	/*replace standard handles*/
	SetStdHandle (STD_INPUT_HANDLE, newstdin);
	SetStdHandle (STD_OUTPUT_HANDLE, newstdout);
	       
	/*start process*/
	compressor_pid= spawnlpe(_P_NOWAIT,"cat",NULL, NULL);
	
	/*restore standard handles*/
	CloseHandle (GetStdHandle (STD_INPUT_HANDLE));
	CloseHandle (GetStdHandle (STD_OUTPUT_HANDLE));
	
	SetStdHandle (STD_INPUT_HANDLE, handles[0]);
	SetStdHandle (STD_OUTPUT_HANDLE, handles[1]);
	
	/*close pipe unneeded and duplicate pipe input to archivefd*/
	dup2(phandles[1], archivefd);
	close(phandles[0]);
	close(phandles[1]);
	
	/*output data to gzip*/
	
	write(archivefd,"abcdefghijklmnopqrstuvwxyz",26);
	
	/*close our handles*/
	close(archivefd);
	
	/*exit*/
	exit(0);
}



--=-JhUJolMo8hJIa2nNeGDX
Content-Type: text/plain; charset=us-ascii

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/
--=-JhUJolMo8hJIa2nNeGDX--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019