A Perl script that internally calls a Linux command and saves the output to a file?

A Perl script that internally calls a Linux command and saves the output to a file?

#!/usr/bin/perl
$command = system("ls /bin/usr/account users/");

my $command = `ps aux`;

my @command = `ps aux`;

my $filename = "MY_FILENAME";
# ...
open FILE, '>>', $filename;
print FILE @command;
close FILE;

use strict;
use warnings;

use Term::ReadKey;

open my $fh, '>', 'temp.txt' or die $!;
print $fh qx(ls /bin/usr/account/users/);

open $fh, '<', 'temp.txt' or die $!;

ReadMode(3);

my $n = 20;
while (<$fh>) {

  print;

  if (--$n == 0) {
    print "-- More  --";
    ReadKey(0);
    $n += 20;
  }
}

ps aux >/tmp/myfile

open (INSTREAM, "ps aux |");

while (<INSTREAM>) { ... }

No comments:

Post a Comment