Run Perl Script on Task Sheduler

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Hugo Vara
    New Member
    • Dec 2010
    • 2

    Run Perl Script on Task Sheduler

    Hi guys,

    I recently start using Perl, so please correct if I say something with no sense :)

    I write a script export some data from AD. The script works ok on Windows Server 2003 R2 on Task Sheduler. The script runs ok on Windows Server 2008 when I run it manually, but when I run it by Task Sheduler the create files are empty. The is no error on task log.

    On the script I'm using 'system' command, may be because this command ? Can someone help me out ?

    Thanks in advance,

    Hugo
  • rovf
    New Member
    • May 2010
    • 41

    #2
    If you suspect system() as the culprit, did you check its return code?

    Comment

    • Hugo Vara
      New Member
      • Dec 2010
      • 2

      #3
      Hi,

      I'm a new user on Perl, I just started yesterday. How can I check that ?

      Thanks

      Hugo

      Comment

      • rovf
        New Member
        • May 2010
        • 41

        #4
        I would just open a file, and append the return value from system() to this file (maybe together with a timestamp and the command to be executed) - provided the value is non-zero.

        For creating files see:
        perldoc -f open
        For writing to a file see:
        perldoc -f print
        For creating a time stamp see:
        perldoc -f localtime

        Comment

        • numberwhun
          Recognized Expert Moderator Specialist
          • May 2007
          • 3467

          #5
          To answer your question about the return code, it would be captured into the special variable: $?

          You can read about all the special variables here.

          Regards,

          Jeff

          Comment

          • rovf
            New Member
            • May 2010
            • 41

            #6
            Well, it is a *return* code after all, so you just take the return value of system(). No need to use $?.

            Comment

            • numberwhun
              Recognized Expert Moderator Specialist
              • May 2007
              • 3467

              #7
              True, was 1/2 asleep when I wrote that. You are correct.


              You simple do this:

              Code:
              my $returncode = system(....);
              $returncode will contain the return value of system(). If its 0, it worked.

              Now, if you are wanting to do something with the system commands you are executing, like use the output of them to do something else in your script, then system() will not work. Instead you will need to use back ticks around the system command.

              Regards,

              Jeff

              Comment

              Working...