Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Piped input to one-liners being truncated

Reply
Thread Tools

Piped input to one-liners being truncated

 
 
tnitzke
Guest
Posts: n/a
 
      08-09-2003
I'm working from Windows 2000 and a lot of my use of Perl involves writing general purpose
batch files and using them from one-liners. The first time I ran into this problem I
was quite mystified until I figured out what was going on. It seems that piped input to a
one-liner that runs a Perl program nested inside a batch file only executes the first line
of input. I wondered if anybody here could shed some light on why this is occuring? I'm able
to work around it, but I'm still curious what is going on.

As an example lets assume I have a file named "servers" with a list of machines running
MS SQL Server. I would like to check the SQL Server version for each machine in the list.
The following two one-liners should produce the same output. Yet the first one stops
after the first machine in the list. Following the two one-liners, is the listing for
"select.bat" that each one-liner runs via "system".


type servers | perl -ne "print; chomp; $cmd=qq(select $_ master \"select \@\@version\"\n); system $cmd;"

perl -e "open S,'servers';while(<S>){print;chomp;$cmd=qq(select $_ master \"select \@\@version\");system $cmd;}"

================== select.bat ================================================== =
@echo off
perl -x -S %0 %*
goto endofperl
#!perl
use DBI;
use strict; use warnings;
die "usage is select <server> <database> <select statement>\n" if $#ARGV < 2;
my ($srvr, $db, $sql) = @ARGV;
my $dsn = "driver=SQL Server;server=$srvr;database=$db;trusted_connectio n=Yes";
my $dbh = DBI->connect("dbi:ODBC:$dsn", '', '');
my $sh = $dbh->prepare($sql);
$sh->execute();
print join "|", @{ $sh->{NAME} }, "\n";
while (my @row = $sh->fetchrow_array) {
print join "|", @row, "\n";
}
__END__
:endofperl
============== end of select.bat ==================================================



--------------
tnitzke
perl -e "($_=qq-dfwbh%nxigh%obchvsf%asfz%voqysfn-)=~tr+%o-za-mn+ a-iJk-lPn-y'+;eval"
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
platform independent piped input stream from system call Danny Challis Ruby 3 12-30-2010 08:25 AM
Reading input piped from windows vim ashen_shugar Python 0 07-22-2010 02:01 AM
Invoking 'diff' from java with piped input David Kensche Java 11 12-10-2004 03:00 PM
reading piped input in Windows Patrick Useldinger Python 4 11-16-2003 02:19 AM
Reading from piped standard input on w2k Yuri Shtil Perl Misc 1 06-30-2003 10:17 PM



Advertisments