From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15823 invoked from network); 23 Jun 1998 20:41:55 -0000 Received: from math.gatech.edu (list@130.207.146.50) by ns1.primenet.com.au with SMTP; 23 Jun 1998 20:41:55 -0000 Received: (from list@localhost) by math.gatech.edu (8.8.5/8.8.5) id QAA00345; Tue, 23 Jun 1998 16:37:39 -0400 (EDT) Resent-Date: Tue, 23 Jun 1998 16:34:50 -0400 (EDT) Message-ID: <19980623163758.05103@astaroth.nit.gwu.edu> Date: Tue, 23 Jun 1998 16:37:58 -0400 From: Sweth Chandramouli To: ZSH Users Subject: easy way to read from stdin ? Mail-Followup-To: ZSH Users Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 0.89 Resent-Message-ID: <"hodch3.0.M1.e51ar"@math> Resent-From: zsh-users@math.gatech.edu X-Mailing-List: archive/latest/1648 X-Loop: zsh-users@math.gatech.edu X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu this is probably just going to show my colossal cluelessness, but is there an easy way to get a zsh script to read from standard input? i have a script that i'd like to convert into a cgi, but that means that rather than reading input from a file, i'd have to have it come from stdin. i tried a "while read ... ; do ... done" loop with no redirection of input, but that didn't seem to work right. what am i missing here? -- sweth. -- Sweth Chandramouli IS Coordinator, The George Washington University / (202) 994 - 8521 (V) / (202) 994 - 0458 (F) * From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16417 invoked from network); 23 Jun 1998 22:09:47 -0000 Received: from math.gatech.edu (list@130.207.146.50) by ns1.primenet.com.au with SMTP; 23 Jun 1998 22:09:47 -0000 Received: (from list@localhost) by math.gatech.edu (8.8.5/8.8.5) id SAA02245; Tue, 23 Jun 1998 18:04:09 -0400 (EDT) Resent-Date: Tue, 23 Jun 1998 18:01:06 -0400 (EDT) From: "Bart Schaefer" Message-Id: <980623150145.ZM1264@candle.brasslantern.com> Date: Tue, 23 Jun 1998 15:01:45 -0700 In-Reply-To: <19980623163758.05103@astaroth.nit.gwu.edu> Comments: In reply to Sweth Chandramouli "easy way to read from stdin ?" (Jun 23, 4:37pm) References: <19980623163758.05103@astaroth.nit.gwu.edu> X-Mailer: Z-Mail (4.0b.820 20aug96) To: Sweth Chandramouli , ZSH Users Subject: Re: easy way to read from stdin ? MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Resent-Message-ID: <"mOa5k2.0.JW.XM2ar"@math> Resent-From: zsh-users@math.gatech.edu X-Mailing-List: archive/latest/1649 X-Loop: zsh-users@math.gatech.edu X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu On Jun 23, 4:37pm, Sweth Chandramouli wrote: } Subject: easy way to read from stdin ? } } this is probably just going to show my colossal cluelessness, but is } there an easy way to get a zsh script to read from standard input? It should be reading everything except the commands themselves from the standard input "by default." However, I'm puzzled when you say: } ... rather than reading input from a file ... What is it that you are doing to cause it to read from a file? That is, when it's not a cgi, how do you run it? } i tried a } "while read ... ; do ... done" loop with no redirection of input, but that } didn't seem to work right. How exactly did it not work? What, if any, flags are you passing to read? (For example, the -q flag will forcibly open /dev/tty ....) } what am i missing here? You can try "read -u0 ..." to force the input to come from file descriptor zero, but I don't know why that would be necessary. -- Bart Schaefer Brass Lantern Enterprises http://www.well.com/user/barts http://www.brasslantern.com From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16785 invoked from network); 23 Jun 1998 22:47:01 -0000 Received: from math.gatech.edu (list@130.207.146.50) by ns1.primenet.com.au with SMTP; 23 Jun 1998 22:47:01 -0000 Received: (from list@localhost) by math.gatech.edu (8.8.5/8.8.5) id SAA02833; Tue, 23 Jun 1998 18:42:56 -0400 (EDT) Resent-Date: Tue, 23 Jun 1998 18:39:09 -0400 (EDT) Message-ID: <19980623184223.11524@astaroth.nit.gwu.edu> Date: Tue, 23 Jun 1998 18:42:23 -0400 From: Sweth Chandramouli To: ZSH Users Subject: Re: Re: easy way to read from stdin ? Mail-Followup-To: ZSH Users References: <19980623163758.05103@astaroth.nit.gwu.edu> <980623150145.ZM1264@candle.brasslantern.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 0.89 In-Reply-To: <980623150145.ZM1264@candle.brasslantern.com> Resent-Message-ID: <"pWMjK3.0.mg.Cw2ar"@math> Resent-From: zsh-users@math.gatech.edu X-Mailing-List: archive/latest/1650 X-Loop: zsh-users@math.gatech.edu X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu On Tue, Jun 23, 1998 at 03:01:45PM -0700, Bart Schaefer wrote: > On Jun 23, 4:37pm, Sweth Chandramouli wrote: > } Subject: easy way to read from stdin ? > } > } this is probably just going to show my colossal cluelessness, but is > } there an easy way to get a zsh script to read from standard input? > > It should be reading everything except the commands themselves from the > standard input "by default." However, I'm puzzled when you say: > > } ... rather than reading input from a file ... > > What is it that you are doing to cause it to read from a file? That is, > when it's not a cgi, how do you run it? i put a "< filename" after the while read loop, so that it would read input from the file "filename". basically, i'm trying to create a mailto form here--it should take the values from the form in question, do some processing on them, return a web page indicating success or failure, and mail the results off to someone using mailx. the processing i was trying to do is the same as what i was doing elsewhere using an already-existing script, so i figured that if i could just cut&paste that script into my new cgi form, and remove the redirection of stdin from a file, everything would work fine. it _does_ work fine from the command line (e.g. "echo 'testing' | myscript.cgi" does what i expect), but when i run it as a form, it acts as though it is getting no input. i do know that the input is, in fact, getting through to the script, however, because i tried replacing my script with a little perl snippet i found elsewhere that basically pumps stdin into a variable and then prints it to screen, and that worked fine. i don't really have the time or patience right now to do what i should do, and actually learn perl, so i was hoping that there was some subtle point about stdin for a shell script that i was missing. if no one else has any ideas, i'll probably wander over to the perl newsgroups and see if anyone can explain exactly what that perl snippet that i stole is doing, to see if maybe i'm not understanding it correctly. (i should probably do that regardless, i guess...) -- sweth. -- Sweth Chandramouli IS Coordinator, The George Washington University / (202) 994 - 8521 (V) / (202) 994 - 0458 (F) * From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17219 invoked from network); 23 Jun 1998 23:57:16 -0000 Received: from math.gatech.edu (list@130.207.146.50) by ns1.primenet.com.au with SMTP; 23 Jun 1998 23:57:16 -0000 Received: (from list@localhost) by math.gatech.edu (8.8.5/8.8.5) id TAA04238; Tue, 23 Jun 1998 19:52:50 -0400 (EDT) Resent-Date: Tue, 23 Jun 1998 19:49:09 -0400 (EDT) From: "Bart Schaefer" Message-Id: <980623165004.ZM1626@candle.brasslantern.com> Date: Tue, 23 Jun 1998 16:50:03 -0700 In-Reply-To: <19980623184223.11524@astaroth.nit.gwu.edu> Comments: In reply to Sweth Chandramouli "Re: Re: easy way to read from stdin ?" (Jun 23, 6:42pm) References: <19980623163758.05103@astaroth.nit.gwu.edu> <980623150145.ZM1264@candle.brasslantern.com> <19980623184223.11524@astaroth.nit.gwu.edu> X-Mailer: Z-Mail (4.0b.820 20aug96) To: Sweth Chandramouli , ZSH Users Subject: Re: easy way to read from stdin ? MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Resent-Message-ID: <"QSplx3.0.B01.kx3ar"@math> Resent-From: zsh-users@math.gatech.edu X-Mailing-List: archive/latest/1651 X-Loop: zsh-users@math.gatech.edu X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu On Jun 23, 6:42pm, Sweth Chandramouli wrote: } Subject: Re: Re: easy way to read from stdin ? } } > What is it that you are doing to cause it to read from a file? That is, } > when it's not a cgi, how do you run it? } i put a "< filename" after the while read loop, so that it would } read input from the file "filename". basically, i'm trying to create a } mailto form here--it should take the values from the form in question, } [...] } but when i run it as a form, it acts as though it is getting no input. Is the form using METHOD=post to send data to the server? Otherwise there isn't any standard input. The enviroment variable CONTENT_LENGTH should tell how many bytes you can expect to read. Try doing local input read -u0k $CONTENT_LENGTH input This should stuff the entire stdin (up to $CONTENT_LENGTH bytes) into the variable "input". The input may be coming to you with "\r\n" line endings, in which case I'm not sure how a plain "read" behaves. -- Bart Schaefer Brass Lantern Enterprises http://www.well.com/user/barts http://www.brasslantern.com