Piped input to one-liners being truncated

Discussion in 'Perl Misc' started by tnitzke, Aug 9, 2003.

  1. tnitzke

    tnitzke Guest

    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_connection=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"
     
    tnitzke, Aug 9, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Kensche
    Replies:
    11
    Views:
    1,142
    David Kensche
    Dec 10, 2004
  2. Patrick Useldinger

    reading piped input in Windows

    Patrick Useldinger, Nov 15, 2003, in forum: Python
    Replies:
    4
    Views:
    1,297
    Georgy Pruss
    Nov 16, 2003
  3. ashen_shugar

    Reading input piped from windows vim

    ashen_shugar, Jul 22, 2010, in forum: Python
    Replies:
    0
    Views:
    258
    ashen_shugar
    Jul 22, 2010
  4. Danny Challis
    Replies:
    3
    Views:
    128
    Kaspar Schiess
    Dec 30, 2010
  5. Larry
    Replies:
    1
    Views:
    121
    Martien Verbruggen
    Feb 3, 2005
Loading...

Share This Page