--Boundary-02=_gZqCAPrbmqy6PrH
Content-Type: text/plain;
charset="utf-8"
Content-Transfer-Encoding: quoted-printable
Content-Description: signed data
Content-Disposition: inline
On Sunday 18 January 2004 8:26 am, Wesley J Landaker wrote:
> On Sunday 18 January 2004 5:39 am, Ferenc Engard wrote:
> > Hi all,
> >
> > Is there a simple way to spawn an external program, feed its stdin,
> > and get its stdout?
> >
> > The problem with popen is, if I want to feed a few MB's of input to
> > it, then it hangs (I suspect that its stdout IO buffer is full)
> > before I could read out its stdout on the next line. So, the
> > following do not work:
> >
> > io=3DIO.popen("externalfilter")
> > io.write(verybigstring)
> > result=3Dio.read
>
> require 'open3'
> Open3.popen3("externalfilter") { |sin,sout,serr|
> sin.write(verybigstring)
> result =3D sout.read
> }
Or (should have mentioned this in my first e-mail) if that still hangs,=20
you might try using Threads:
require 'open3'
Open3.popen3("externalfilter") { |sin,sout,serr|
threads =3D []
threads << Thread.new {
sin.write(verybigstring)
}
threads << Thread.new {
result =3D sout.read
}
threads.each {|t| t.join }
}
=2D-=20
Wesley J. Landaker -
OpenPGP FP: 4135 2A3B 4726 ACC5 9094 0097 F0A9 8A4C 4CD6 E3D2
--Boundary-02=_gZqCAPrbmqy6PrH
Content-Type: application/pgp-signature
Content-Description: signature
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
iD8DBQBACqZg8KmKTEzW49IRAig3AJ47xcktxRif46Koj5jfze TPa2rUDACfTLNr
OrQEmw9R0/vWZq8DcaAS9DM=
=Xy10
-----END PGP SIGNATURE-----
--Boundary-02=_gZqCAPrbmqy6PrH--