From: Stuart Holden Date: 2006-05-18T21:16:15+09:00 Subject: Command Line Processing / Pipes ------_=_NextPart_001_01C67A74.B32F5046 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: quoted-printable Hi, I'm trying to create a script that that is flexible enough to accept input that is read from a file whose filename is passed as a command line argument, or from STDIN via a pipe.=20 (This is on a WinXP platform rather than Unix) By way of a simple example, I want both of the following to produce the same results: 1: myScript.rb *.txt 2: cat *.txt | myScript.rb I have had some joy with the first approach... while line =3D ARGF.gets=20 #-- Do the interesting stuff here... or just print the line. print line=09 end=09 However, I cannot get anything to work for the pipe approach. I thought that this would handle piped along STDIN while gets() line =3D $_ print line end but it chucks the following error: U:\dev\WM&CAPS\capsfiles>cat testfile.caps | caps.rb c:/scripts/caps.rb:1:in `gets': Bad file descriptor (Errno::EBADF) from c:/scripts/caps.rb:1 It does work for STDIO that comes in from the console, but not the pipe. Oddly (for me), this code works when you pass the filename on the command line.=20 Apologies for my newbie stupidity. I've had a good half hours google for help on this but haven't had any luck.=20 Any help would be appreciated.=20 Thanks, Stuart Holden Senior Analyst Developer / IT Technical Services - Baring Asset Management (London) Tel Direct: +44 (0)20-7214 1932 Fax Direct: +44 (0)20-7214 1634 E-mail: Stuart.Holden@Baring-Asset.com Web: http://www.baring-asset.com =20

This Email may c= ontain confidential and privileged information and is intended for the use = of the addressee(s) only. If you are not the intended recipient please no= tify the sender and delete the Email from your system. It should not be tra= nsmitted to any other person without the consent of the sender. Additional = important notifications regarding Email transmissions from and to members o= f Baring Asset Management can be accessed at http://www.barings.com/email/index.hcst

 

------_=_NextPart_001_01C67A74.B32F5046--