[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Stefan Gremm

3/24/2008 2:52:00 PM

Hello,

first excuse me my bad english.

i have write a little send_mail script. now i pipe the messagetext from
another program, like cat /var/mailtext| send-mail.rb

the program source:

smtp_message = ""

temp = $stdin

temp.each do |f|
smtp_message += f
end

this is runing very well, but when no text is in the pipe, the program
is waiting for input.

my question is, how can i ask, if text in $stdin, without the program is
waitung for input.

ciao

Stefan
--
====================================================================
Stefan Gremm, Trebur, Germany
Key fingerprint = BBBD 6645 F8B4 FE73 22FC D2F4 B4E6 5B48 60A2 82D9
====================================================================


9 Answers

Rodrigo Bermejo

3/24/2008 5:11:00 PM

0

Stefan Gremm wrote:
> Hello,
>
> first excuse me my bad english.
>
> i have write a little send_mail script. now i pipe the messagetext from
> another program, like cat /var/mailtext| send-mail.rb
>
> the program source:
>
> smtp_message = ""
>
> temp = $stdin
>
> temp.each do |f|
> smtp_message += f
> end
>
> this is runing very well, but when no text is in the pipe, the program
> is waiting for input.
>
> my question is, how can i ask, if text in $stdin, without the program is
> waitung for input.
>
> ciao
>
> Stefan


Try the -n option
> -n assume 'while gets(); ... end' loop around your
script


#code
smtp_message = ""
$_.each do |f|
smtp_message += f
end
#endcode


cat /var/mailtext| ruby -n send-mail.rb

-rb


--
Posted via http://www.ruby-....

Stefan Gremm

3/24/2008 5:47:00 PM

0


Am Dienstag, den 25.03.2008, 02:11 +0900 schrieb Rodrigo Bermejo:
> Try the -n option
> > -n assume 'while gets(); ... end' loop around your
> script
>
>
> #code
> smtp_message = ""
> $_.each do |f|
> smtp_message += f
> end
> #endcode
>
>
> cat /var/mailtext| ruby -n send-mail.rb

thanks for the answer, but when i start my script is coming the folowing
error

undefined method `each' for nil:NilClass (NoMethodError)

and my command parser brings failure

ciao

Stefan
--
====================================================================
Stefan Gremm, Trebur, Germany
Key fingerprint = BBBD 6645 F8B4 FE73 22FC D2F4 B4E6 5B48 60A2 82D9
====================================================================


Rodrigo Bermejo

3/24/2008 6:12:00 PM

0

Stefan Gremm wrote:
> Am Dienstag, den 25.03.2008, 02:11 +0900 schrieb Rodrigo Bermejo:
>> #endcode
>>
>>
>> cat /var/mailtext| ruby -n send-mail.rb
>
> thanks for the answer, but when i start my script is coming the folowing
> error
>
> undefined method `each' for nil:NilClass (NoMethodError)
>
> and my command parser brings failure
>
> ciao
>
> Stefan

did you change ?:
> temp.each do |f|
with
> $_.each do |f|
--
Posted via http://www.ruby-....

Stefan Gremm

3/24/2008 6:18:00 PM

0


Am Dienstag, den 25.03.2008, 03:12 +0900 schrieb Rodrigo Bermejo:
> did you change ?:
> > temp.each do |f|
> with
> > $_.each do |f|
> --

yes, now i have
$stdin.each do |f| unless $stdin == nil
smtp_message += f
end
end

but when i have nothing in $stdin, the program is waiting

Ciao

Stefan

--
====================================================================
Stefan Gremm, Trebur, Germany
Key fingerprint = BBBD 6645 F8B4 FE73 22FC D2F4 B4E6 5B48 60A2 82D9
====================================================================


Rodrigo Bermejo

3/24/2008 8:45:00 PM

0

weird it is working for me....

>touch 1
#create empty file

>cat 1| 2.rb
: undefined method `each' for nil:NilClass (NoMethodError)

>cat 1| ruby -n 2.rb
>#No errors


You need to specify the -n option.


#############
>cat 2.rb
smtp_message = ""

$_.each do |f|
smtp_message += f
end
p smtp_message
--
Posted via http://www.ruby-....

Eric Hodel

3/24/2008 11:50:00 PM

0

On Mar 24, 2008, at 07:51 AM, Stefan Gremm wrote:
> my question is, how can i ask, if text in $stdin, without the
> program is
> waitung for input.

Here's one way, but it isn't foolproof.

$ ruby -e 'p $stdin.tty?'
true
$ ruby -e 'p $stdin.tty?' < /dev/null
false
$ cat /dev/null | ruby -e 'p $stdin.tty?'
false

Stefan Gremm

3/25/2008 8:43:00 AM

0


Am Dienstag, den 25.03.2008, 08:50 +0900 schrieb Eric Hodel:
> Here's one way, but it isn't foolproof.
>
> $ ruby -e 'p $stdin.tty?'
> true
> $ ruby -e 'p $stdin.tty?' < /dev/null
> false
> $ cat /dev/null | ruby -e 'p $stdin.tty?'
> false

eric, thank you for your answer.

But, when starting the program without pipe, the result is true too

Mhmm, my program becoms the messagetext over pipe or over
commandparameter ,if over pipe, all is good, if over parameter, the
program hangs.

Ciao

Stefan
--
====================================================================
Stefan Gremm, Trebur, Germany
Key fingerprint = BBBD 6645 F8B4 FE73 22FC D2F4 B4E6 5B48 60A2 82D9
====================================================================


Sweetbac

3/18/2010 4:20:00 PM

0


"desdave" <dnabucholtz@adelphia.net> wrote in message
news:2ee997be-82c3-4598-b875-

> Just wondering if anyone pondered that this was a special occasion for
> PHIL, his 70th Birthday party and that perhaps the choices of
> musicians was geared towards his enjoyment, and not yours?

* Then WHY was my credit card charged $96?
explain me that.


> obviously has great respect for Jackie, Chris and John Molo... he has
> chosen to play extensively with them, so it actually makes perfect
> sense to me. You all were allowed to take part in a party thrown for
> a great guy we have always loved,

* I did business with Phil...I trusted Phil...
but I never LOVED phil.


> this could easily had been a 'backyard jam' at Phils place
> in the hills for his personal close friends, thus excluding you.

* I've been in Phils back yard.
Between the tattered volleyball net and the rottweiler poop,
there's not a lot to recommend.

> Dave from Chino


Edwin Hurwitz

3/19/2010 1:54:00 AM

0

In article
<c86f9275-a68f-4950-b69b-f4d0e553f0b0@s25g2000prd.googlegroups.com>,
"J.C. Martin" <avantgrape@gmail.com> wrote:

> On Mar 16, 11:23?am, "3jane." <q3j...@yahoo.com> wrote:
> > On Mar 16, 7:59?am, booie <ba_ba_b0...@webtv.net> wrote:
> >
> > >http://www.archive.org/details/furthur2010-03...
> >
> > > this sounds pretty good
> >
> > > booie........
> >
> > Looking at the set list, I'd like to get some input from the rmgders
> > in attendance. ?It looks on paper like the Chris Robinson/Jackie
> > Greene show-JK only sang lead on one song?-how did that go down? ?I
> > know there were a lot of detractors from his time with P&F, how did he
> > fit in with these guys? ?How did 4 guitars sound on stage, did they
> > avoid the clutter and give each other enough room? ? In general do you
> > think having a JG or CR as a full time member would improve Further or
> > is it better as is?
>
>
> I prefer the band as is myself. The set list was geared IMO towards
> less difficult tunes in order to keep Jackie on stage. When they
> busted into a song like Unbroken Chain, Jackie was absent. The kid is
> pretty much a roots-rock-based player.
>
> -JC

So was Pig.

Edwin