Professional Web Applications Themes

redirecting the output of a command to a file - PERL Beginners

What is your real problem? open(IN, "myCommand |"); open(OUT, ">$outputFileName"); print OUT join("", <IN>); close OUT; close IN; -----Original Message----- From: Ivan Novick [mailto:ivan.novickmakoglobal.com] Sent: Tuesday, August 26, 2003 1:47 PM To: 'Marcos.Rebeloeurocopter.com'; [email]beginnersperl.org[/email] Subject: RE: redirecting the output of a command to a file Is there no other way some perl syntax to redirect to a file the output of a command? -----Original Message----- From: [email]Marcos.Rebeloeurocopter.com[/email] [ mailto:Marcos.Rebeloeurocopter.com <mailto:Marcos.Rebeloeurocopter.com> ] Sent: Tuesday, August 26, 2003 7:14 AM To: Ivan Novick; [email]beginnersperl.org[/email] Subject: RE: redirecting the output of a command to a file system("myCommand > myFile"); must work -----Original Message----- ...

  1. #1

    Default RE: redirecting the output of a command to a file

    What is your real problem?

    open(IN, "myCommand |");
    open(OUT, ">$outputFileName");
    print OUT join("", <IN>);
    close OUT;
    close IN;



    -----Original Message-----
    From: Ivan Novick [mailto:ivan.novickmakoglobal.com]
    Sent: Tuesday, August 26, 2003 1:47 PM
    To: 'Marcos.Rebeloeurocopter.com'; [email]beginnersperl.org[/email]
    Subject: RE: redirecting the output of a command to a file



    Is there no other way some perl syntax to redirect to a file the output of a
    command?

    -----Original Message-----
    From: [email]Marcos.Rebeloeurocopter.com[/email] [ mailto:Marcos.Rebeloeurocopter.com
    <mailto:Marcos.Rebeloeurocopter.com> ]
    Sent: Tuesday, August 26, 2003 7:14 AM
    To: Ivan Novick; [email]beginnersperl.org[/email]
    Subject: RE: redirecting the output of a command to a file


    system("myCommand > myFile");
    must work

    -----Original Message-----
    From: Ivan Novick [ mailto:ivan.novickmakoglobal.com
    <mailto:ivan.novickmakoglobal.com> ]
    Sent: Tuesday, August 26, 2003 1:11 PM
    To: [email]beginnersperl.org[/email]
    Subject: redirecting the output of a command to a file


    Hi,

    does anyone know syntax to run a command and redirect its output directly to

    a file?

    Equivalent to myCommand > myFile in shell

    Thanks,

    Ivan

    Marcos Rebelo Guest

  2. #2

    Default Re: redirecting the output of a command to a file

    Ivan Novick wrote:
    >
    > Hi,
    Hello,
    > does anyone know syntax to run a command and redirect its output directly to
    > a file?
    >
    > Equivalent to myCommand > myFile in shell
    open my $pipe, 'myCommand |' or die "Cannot open pipe from myCommand:
    $!";
    open my $fh, '>', 'myFile' or die "Cannot open myFile: $!";
    print $fh while <$pipe>;
    close $pipe or die "Cannot close pipe from myCommand: $!";


    Or if myCommand outputs "binary" data.

    open my $pipe, 'myCommand |' or die "Cannot open pipe from myCommand:
    $!";
    binmode $pipe;
    open my $fh, '>', 'myFile' or die "Cannot open myFile: $!";
    binmode $fh;
    print $fh while read $pipe, $_, 1024;
    close $pipe or die "Cannot close pipe from myCommand: $!";



    John
    --
    use Perl;
    program
    fulfillment
    John W. Krahn Guest

Similar Threads

  1. Redirecting zip file
    By nagaraj in forum ASP
    Replies: 3
    Last Post: September 15th, 10:48 AM
  2. Output from external command under Win2K
    By Neil Palmer in forum PERL Miscellaneous
    Replies: 1
    Last Post: September 4th, 03:24 PM
  3. Output of who command (again)
    By Jean-Pierre Radley in forum SCO
    Replies: 3
    Last Post: August 5th, 01:07 PM
  4. errpt command gives no output, why?
    By pui ming Wong in forum AIX
    Replies: 3
    Last Post: July 30th, 02:01 PM
  5. Error when redirecting output to Excel
    By Tammy B. in forum ASP
    Replies: 1
    Last Post: July 4th, 12:54 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139