By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,240 Members | 1,287 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,240 IT Pros & Developers. It's quick & easy.

Passing variables from a perl script to calling batch script

P: 1
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
Mar 27 '08 #1
Share this Question
Share on Google+
5 Replies


P: 89
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....
Mar 27 '08 #2

kalyanrajsista
P: 7
Expand|Select|Wrap|Line Numbers
  1. exec(PATH_TO_THE_PROGRAM);
  2. $result = system(PATH_TO_THE_PROGRAM); 
  3.  
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:

Expand|Select|Wrap|Line Numbers
  1. $result = `PATH_TO_THE_PROGRAM`;
  2.  
Mar 28 '08 #3

P: 89
Expand|Select|Wrap|Line Numbers
  1. exec(PATH_TO_THE_PROGRAM);
  2. $result = system(PATH_TO_THE_PROGRAM); 
  3.  
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:

Expand|Select|Wrap|Line Numbers
  1. $result = `PATH_TO_THE_PROGRAM`;
  2.  

can this backtick be used in windows platform.
Mar 29 '08 #4

KevinADC
Expert 2.5K+
P: 4,059
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.
Mar 29 '08 #5

KevinADC
Expert 2.5K+
P: 4,059
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:

Expand|Select|Wrap|Line Numbers
  1. print $CurMon, $PriorMon;
that sends them to STDOUT and to your batch program.
Mar 29 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.