How to run system commands through perl script in Windows Server 2008 R2?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mangala Amargol
    New Member
    • Jan 2011
    • 4

    How to run system commands through perl script in Windows Server 2008 R2?

    For example,runnig "ipconfig" command through perl script and printing it on web browser.
    Code:
    my $cmd = "ipconfig";
    my $output = `$cmd`;
    print $output;
    Above code works fine in Windows Server 2003,but $output is null in Windows Server 2008 R2.

    Done necessary settings in IIS for perl,is there additional settings in windows server 2008 R2 for perl?
    Is there a way to make above mentioned code to work in Windows Server 2008 R2.
    Using perl 5.6 version.


    Appreciate your help.
    Last edited by numberwhun; Jan 29 '11, 03:28 AM. Reason: Please use code tags!
  • numberwhun
    Recognized Expert Moderator Specialist
    • May 2007
    • 3467

    #2
    @output will definitely be null. In the code you provided above, you are storing it in $output. Two totally different containers.

    Comment

    • Mangala Amargol
      New Member
      • Jan 2011
      • 4

      #3
      Sorry ,@output is typo mistake,it is $output.

      Comment

      • chorny
        Recognized Expert New Member
        • Jan 2008
        • 80

        #4
        1. Try running it from command line. Does it work?

        2. Try using system instead of ``. Does it return any error?

        Comment

        • Mangala Amargol
          New Member
          • Jan 2011
          • 4

          #5
          Thanks for quick reply
          1.It does works through command prompt.
          2.system returns 0.

          Comment

          • chorny
            Recognized Expert New Member
            • Jan 2008
            • 80

            #6
            It is possible that IIS runs command with lowered privileges.

            Try running it as `$cmd 2>&1`. Does it return any error message?

            Comment

            • Mangala Amargol
              New Member
              • Jan 2011
              • 4

              #7
              It returns NULL,
              How can I increase previlages in IIS?
              Iam trying to run web Application in windows server 2008 R2 which works fine in Windows Server 2003.Web app uses both perl and cgi.Several pages are not working because of system command call using backtik.
              One more thing I tried redirecting output to file,which is working.Since there are lot files using system command I do not want do this.
              Need your valuable suggestions.

              Comment

              • Peter Brodt
                New Member
                • Jun 2011
                • 1

                #8
                we have got the same problem. Have you found a solution or at least the reasons why the backtick command in perl suddenly doesn't work with windows server 2008 r2.

                Comment

                • RonB
                  Recognized Expert Contributor
                  • Jun 2009
                  • 589

                  #9
                  Try specifying the full path or use a module which extracts the info from the registry.

                  Win32::IPConfig

                  Comment

                  Working...