Loading ...
Sorry, an error occurred while loading the content.

Re: [PBML] Using System Command in Perl

Expand Messages
  • Jeff Soules
    Maybe the backtick operator ` `? (Backtick on my keyboard is the tilde key ~ without shift, but it might be different on your keyboard). ... You d do my
    Message 1 of 29 , Jun 24, 2009
    • 0 Attachment
      Maybe the backtick operator ` `? (Backtick on my keyboard is the
      tilde key ~ without shift, but it might be different on your
      keyboard).

      So in place of:

      > system 'CTMORDER -SCHEDTAB EM-$ENV-REPORT-LOGS -JOBNAME
      > EM-$ENV-$Client_Key-AAL-EMAIL -ODATE ODAT -FORCE Y';

      You'd do

      my $result = `CTMORDER -SCHEDTAB EM-$ENV-REPORT-LOGS -JOBNAME
      EM-$ENV-$Client_Key-AAL-EMAIL -ODATE ODAT -FORCE Y`;

      and then look in $result for whatever the other utility would normally
      print on the screen.

      $? is supposed to be set the same way for system() as for the backtick
      operator, but maybe your other Windows program isn't returning a
      status properly or something?

      On Tue, Jun 23, 2009 at 9:33 PM, Kevin Patterson<kpatters@...> wrote:
      >
      >
      >
      >
      > Hi,
      >
      > I am writing a perl program to call/ execute another windows program
      >
      > Using the system command.
      >
      > I am trying to get/print the results to see if the command worked.
      >
      > Is there a way to capture the output of what the program ran??
      >
      > I tried using system ' ' and system(). I get the same results.. nothing..
      >
      > Here is my code so far.
      >
      > #!/usr/bin/perl
      >
      > # use strict;
      >
      > # use warnings;
      >
      > @client = qw(EM AS);
      >
      > #@client = qw(EM HR KR AS BF DB);
      >
      > my $eNV = "QW-D";
      >
      > my $T = '"';
      >
      > foreach $Client_Key (@client)
      >
      > {
      >
      > system 'CTMORDER -SCHEDTAB EM-$ENV-REPORT-LOGS -JOBNAME
      > EM-$ENV-$Client_Key-AAL-EMAIL -ODATE ODAT -FORCE Y';
      >
      > print "Status: $? $!\n";
      >
      > }
      >
      > [Non-text portions of this message have been removed]
      >
      >
    • Kevin Patterson
      I TRIED IT THIS WAY.. INCLUDING WITH THE BACK LASHES. But I still get nothing.. And I show nothing ran in task manager.. open my $command, e: BMC
      Message 2 of 29 , Jun 24, 2009
      • 0 Attachment
        I TRIED IT THIS WAY.. INCLUDING WITH THE BACK LASHES. But I still get
        nothing.. And I show nothing ran in task manager..



        open my $command, "e:\BMC Software\CONTROL-M
        Server\Ctm_server\Exe\CTMORDER.exe -SCHEDTAB EM-QW-D-REPORT-LOGS -JOBNAME
        EM-QW-D-AS-AAL-EMAIL -ODATE ODAT -FORCE Y";



        while (my $line = <$command>) {



        print $line; # you could do other stuff with this...

        }



        close $command;



        exit;



        From: perl-beginner@yahoogroups.com [mailto:perl-beginner@yahoogroups.com]
        On Behalf Of Jeff Soules
        Sent: Wednesday, June 24, 2009 9:58 AM
        To: perl-beginner@yahoogroups.com
        Subject: Re: [PBML] Using System Command in Perl








        Maybe the backtick operator ` `? (Backtick on my keyboard is the
        tilde key ~ without shift, but it might be different on your
        keyboard).

        So in place of:

        > system 'CTMORDER -SCHEDTAB EM-$ENV-REPORT-LOGS -JOBNAME
        > EM-$ENV-$Client_Key-AAL-EMAIL -ODATE ODAT -FORCE Y';

        You'd do

        my $result = `CTMORDER -SCHEDTAB EM-$ENV-REPORT-LOGS -JOBNAME
        EM-$ENV-$Client_Key-AAL-EMAIL -ODATE ODAT -FORCE Y`;

        and then look in $result for whatever the other utility would normally
        print on the screen.

        $? is supposed to be set the same way for system() as for the backtick
        operator, but maybe your other Windows program isn't returning a
        status properly or something?

        On Tue, Jun 23, 2009 at 9:33 PM, Kevin Patterson<kpatters@...
        <mailto:kpatters%40berkeley.edu> > wrote:
        >
        >
        >
        >
        > Hi,
        >
        > I am writing a perl program to call/ execute another windows program
        >
        > Using the system command.
        >
        > I am trying to get/print the results to see if the command worked.
        >
        > Is there a way to capture the output of what the program ran??
        >
        > I tried using system ' ' and system(). I get the same results.. nothing..
        >
        > Here is my code so far.
        >
        > #!/usr/bin/perl
        >
        > # use strict;
        >
        > # use warnings;
        >
        > @client = qw(EM AS);
        >
        > #@client = qw(EM HR KR AS BF DB);
        >
        > my $eNV = "QW-D";
        >
        > my $T = '"';
        >
        > foreach $Client_Key (@client)
        >
        > {
        >
        > system 'CTMORDER -SCHEDTAB EM-$ENV-REPORT-LOGS -JOBNAME
        > EM-$ENV-$Client_Key-AAL-EMAIL -ODATE ODAT -FORCE Y';
        >
        > print "Status: $? $!\n";
        >
        > }
        >
        > [Non-text portions of this message have been removed]
        >
        >





        [Non-text portions of this message have been removed]
      • vishal thakur
        When executing this command, don t forget to redirect the STDERR to STDIO, else you won t be able to figure out the reason why command has failed, so i will
        Message 3 of 29 , Jun 25, 2009
        • 0 Attachment
          When executing this command, don't forget to redirect the STDERR to STDIO,
          else you won't be able to figure out the reason why command has failed, so i
          will suggest following
          my $result = `CTMORDER -SCHEDTAB EM-$ENV-REPORT-LOGS -JOBNAME
          EM-$ENV-$Client_Key-AAL-EMAIL -ODATE ODAT -FORCE Y 2>&1`;

          so result will hold any output message or error message and to know the
          status of the command just echo "$?"

          On Wed, Jun 24, 2009 at 10:27 PM, Jeff Soules <soules@...> wrote:

          >
          >
          > Maybe the backtick operator ` `? (Backtick on my keyboard is the
          > tilde key ~ without shift, but it might be different on your
          > keyboard).
          >
          > So in place of:
          >
          >
          > > system 'CTMORDER -SCHEDTAB EM-$ENV-REPORT-LOGS -JOBNAME
          > > EM-$ENV-$Client_Key-AAL-EMAIL -ODATE ODAT -FORCE Y';
          >
          > You'd do
          >
          > my $result = `CTMORDER -SCHEDTAB EM-$ENV-REPORT-LOGS -JOBNAME
          > EM-$ENV-$Client_Key-AAL-EMAIL -ODATE ODAT -FORCE Y`;
          >
          > and then look in $result for whatever the other utility would normally
          > print on the screen.
          >
          > $? is supposed to be set the same way for system() as for the backtick
          > operator, but maybe your other Windows program isn't returning a
          > status properly or something?
          >
          > On Tue, Jun 23, 2009 at 9:33 PM, Kevin Patterson<kpatters@...<kpatters%40berkeley.edu>>
          > wrote:
          > >
          > >
          > >
          > >
          > > Hi,
          > >
          > > I am writing a perl program to call/ execute another windows program
          > >
          > > Using the system command.
          > >
          > > I am trying to get/print the results to see if the command worked.
          > >
          > > Is there a way to capture the output of what the program ran??
          > >
          > > I tried using system ' ' and system(). I get the same results.. nothing..
          > >
          > > Here is my code so far.
          > >
          > > #!/usr/bin/perl
          > >
          > > # use strict;
          > >
          > > # use warnings;
          > >
          > > @client = qw(EM AS);
          > >
          > > #@client = qw(EM HR KR AS BF DB);
          > >
          > > my $eNV = "QW-D";
          > >
          > > my $T = '"';
          > >
          > > foreach $Client_Key (@client)
          > >
          > > {
          > >
          > > system 'CTMORDER -SCHEDTAB EM-$ENV-REPORT-LOGS -JOBNAME
          > > EM-$ENV-$Client_Key-AAL-EMAIL -ODATE ODAT -FORCE Y';
          > >
          > > print "Status: $? $!\n";
          > >
          > > }
          > >
          > > [Non-text portions of this message have been removed]
          > >
          > >
          >
          >



          --
          Regards
          Vishal Thakur
          +919923206953


          [Non-text portions of this message have been removed]
        • Shlomi Fish
          ... In that case, make sure you use String-ShellQuote: http://search.cpan.org/dist/String-ShellQuote/ Alternatively use open -| , @list which is only
          Message 4 of 29 , Jun 25, 2009
          • 0 Attachment
            On Wednesday 24 June 2009 19:57:50 Jeff Soules wrote:
            > Maybe the backtick operator ` `? (Backtick on my keyboard is the
            > tilde key ~ without shift, but it might be different on your
            > keyboard).
            >
            > So in place of:
            > > system 'CTMORDER -SCHEDTAB EM-$ENV-REPORT-LOGS -JOBNAME
            > > EM-$ENV-$Client_Key-AAL-EMAIL -ODATE ODAT -FORCE Y';
            >
            > You'd do
            >
            > my $result = `CTMORDER -SCHEDTAB EM-$ENV-REPORT-LOGS -JOBNAME
            > EM-$ENV-$Client_Key-AAL-EMAIL -ODATE ODAT -FORCE Y`;
            >

            In that case, make sure you use String-ShellQuote:

            http://search.cpan.org/dist/String-ShellQuote/

            Alternatively use open '-|', @list which is only available on Windows.

            Regards,

            Shlomi Fish

            > and then look in $result for whatever the other utility would normally
            > print on the screen.
            >
            > $? is supposed to be set the same way for system() as for the backtick
            > operator, but maybe your other Windows program isn't returning a
            > status properly or something?
            >
            > On Tue, Jun 23, 2009 at 9:33 PM, Kevin Patterson<kpatters@...>
            wrote:
            > > Hi,
            > >
            > > I am writing a perl program to call/ execute another windows program
            > >
            > > Using the system command.
            > >
            > > I am trying to get/print the results to see if the command worked.
            > >
            > > Is there a way to capture the output of what the program ran??
            > >
            > > I tried using system ' ' and system(). I get the same results.. nothing..
            > >
            > > Here is my code so far.
            > >
            > > #!/usr/bin/perl
            > >
            > > # use strict;
            > >
            > > # use warnings;
            > >
            > > @client = qw(EM AS);
            > >
            > > #@client = qw(EM HR KR AS BF DB);
            > >
            > > my $eNV = "QW-D";
            > >
            > > my $T = '"';
            > >
            > > foreach $Client_Key (@client)
            > >
            > > {
            > >
            > > system 'CTMORDER -SCHEDTAB EM-$ENV-REPORT-LOGS -JOBNAME
            > > EM-$ENV-$Client_Key-AAL-EMAIL -ODATE ODAT -FORCE Y';
            > >
            > > print "Status: $? $!\n";
            > >
            > > }
            > >
            > > [Non-text portions of this message have been removed]

            --
            -----------------------------------------------------------------
            Shlomi Fish http://www.shlomifish.org/
            Freecell Solver - http://fc-solve.berlios.de/

            God gave us two eyes and ten fingers so we will type five times as much as we
            read.
          Your message has been successfully submitted and would be delivered to recipients shortly.