Passing variables from a perl script to calling batch script

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • veeraiah
    New Member
    • Mar 2008
    • 1

    Passing variables from a perl script to calling batch script

    Hi,

    I am new to PERL Scripting, i need your help with one of the problem i am having.

    I am having a PERL Script which has two variables $CurMon and $PriorMon. a Windows batch script calls this PERL Script. I want to return the values of the these two variables to the windows batch script. Can i do this? Please give me some suggestions.

    Thank You

    Chow
  • rohitbasu77
    New Member
    • Feb 2008
    • 89

    #2
    Originally posted by veeraiah
    Hi,

    I am new to PERL Scripting, i need your help with one of the problem i am having.

    I am having a PERL Script which has two variables $CurMon and $PriorMon. a Windows batch script calls this PERL Script. I want to return the values of the these two variables to the windows batch script. Can i do this? Please give me some suggestions.

    Thank You

    Chow
    i do have a question also, its just reverse one:

    There is a batch program in windows.
    The program name is "built".
    I can run the batch manually, but now i want to run in within a perl script.

    How can i do that in Microsoft Windows Enviroment....

    Comment

    • kalyanrajsista
      New Member
      • Mar 2008
      • 7

      #3
      Code:
      exec(PATH_TO_THE_PROGRAM);
      $result = system(PATH_TO_THE_PROGRAM);
      Both Perl's exec() function and system() function execute a system shell command. The big difference is that system() creates a fork process and waits to see if the command succeeds or fails - returning a value. exec() does not return anything, it simply executes the command. Neither of these commands should be used to capture the output of a system call. If your goal is to capture output, you should use the backtick operator:

      Code:
      $result = `PATH_TO_THE_PROGRAM`;

      Comment

      • rohitbasu77
        New Member
        • Feb 2008
        • 89

        #4
        Originally posted by kalyanrajsista
        Code:
        exec(PATH_TO_THE_PROGRAM);
        $result = system(PATH_TO_THE_PROGRAM);
        Both Perl's exec() function and system() function execute a system shell command. The big difference is that system() creates a fork process and waits to see if the command succeeds or fails - returning a value. exec() does not return anything, it simply executes the command. Neither of these commands should be used to capture the output of a system call. If your goal is to capture output, you should use the backtick operator:

        Code:
        $result = `PATH_TO_THE_PROGRAM`;

        can this backtick be used in windows platform.

        Comment

        • KevinADC
          Recognized Expert Specialist
          • Jan 2007
          • 4092

          #5
          If you are using perl than the answer is yes. If you are not using perl then you need to ask on the appropriate forum how to do whatever it is you are wanting to do.

          Comment

          • KevinADC
            Recognized Expert Specialist
            • Jan 2007
            • 4092

            #6
            Originally posted by veeraiah
            Hi,

            I am new to PERL Scripting, i need your help with one of the problem i am having.

            I am having a PERL Script which has two variables $CurMon and $PriorMon. a Windows batch script calls this PERL Script. I want to return the values of the these two variables to the windows batch script. Can i do this? Please give me some suggestions.

            Thank You

            Chow
            I think all you need to do is print the variables within your perl program:

            Code:
            print $CurMon, $PriorMon;
            that sends them to STDOUT and to your batch program.

            Comment

            Working...