From spikeh at mweb.co.za Wed Dec 22 06:42:32 2004 From: spikeh at mweb.co.za (Spike) Date: Wed Dec 22 06:42:38 2004 Subject: [Za-pm] no STDIN In-Reply-To: <1098785152.1113.45.camel@jackie.afribiz.co.za> References: <1098785152.1113.45.camel@jackie.afribiz.co.za> Message-ID: <6.2.0.14.2.20041222142504.04311350@pop3.mweb.co.za> Hi All I have a small perl script called "male" which is used in much the same way, with similar options as "mail". That is you can do things like echo"boo" | mail spike@mweb.com But male allows a few extra options that I find useful like you can set the reply address and Cc etc from the Command line too. i.e cat myfile.txt | male -c cc@mweb.com -r sender@spam.com spike@mweb.com The most useful bit being the -a that allows me to send a file as an attachment. Now this is where my problem is. It all works fine as long as I cat myfile | male .... or echo"my message to you" | male ...... But often I don't want to send a message body - i just want to send an attached file. male -a myfile spike@mweb.com The problem is that it just hangs waiting for something on STDIN. I capture the STDIN with while () { $body .= $_; } In have also tried @body = ; and if() but as soon as we get a it waits for one! Anyone have an idea on how I can get the script to realize when there will be no STDIN - (other than another switch on the Command line)? -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.pm.org/pipermail/za-pm/attachments/20041222/6564fb17/attachment.htm From jason at dart.co.za Wed Dec 29 17:57:27 2004 From: jason at dart.co.za (Jason Armstrong) Date: Wed Dec 29 17:57:33 2004 Subject: Fwd: Re: [Za-pm] no STDIN Message-ID: <20041229235727.GC17509@riverdrums.com> [ Spike: Dec 22 14:45 ] > male -a myfile spike@mweb.com > > The problem is that it just hangs waiting for something on STDIN. > Anyone have an idea on how I can get the script to realize when there > will be no STDIN - (other than another switch on the Command line)? Unfortunately, if you need to read anything from STDIN, then your script is going to wait until it reads something. You could just press ^D after the command to get the script to stop reading. Or you could reverse the order of command line switches ie provide a switch that will tell you 'read from stdin': $ male -a myfile -s spike@mweb.com The -s could indicate that you wanted to add text to your message. Then you could do something like: if ($readstdin) { while () { . . } } Or you could have another switch eg '-a myfile' could mean 'attach my file and read from stdin', whereas '-i myfile' could mean 'attach my file and send immediately'. Another way would be to implement a timeout on stdin, using select(). For example: my $in = ''; vec($in, fileno(STDIN), 1) = 1; if (select($in, undef, undef, 2)) { while () { .... } } Would wait for 2 seconds for input on stdin, and then timeout. Look at the documentation for select (perldoc -f select) for more information. -- Jason Armstrong