471,873 Members | 1,896 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,873 software developers and data experts.

get return value from batch

Hi All,
I would like to run a batch file from perl and ger the reutun value from the batch file,
How can I do it?

I try to run system or exec but it didn’t work

Any idea?

$val=system("test.bat");

$val=exec “test.bat”;

Thanks
Ronen
May 17 '07 #1
5 9213
AdrianH
1,251 Expert 1GB
Hi All,
I would like to run a batch file from perl and ger the reutun value from the batch file,
How can I do it?

I try to run system or exec but it didn’t work

Any idea?

$val=system("test.bat");

$val=exec “test.bat”;

Thanks
Ronen
$val = system("cmd /c test.bat");

Adrian
May 17 '07 #2
KevinADC
4,059 Expert 2GB
exec() - The exec() function executes a system command AND NEVER RETURNS

system() - The return value is the exit status of the program as returned by the wait() call.



If you want output returned (not exit status) you have to use backtiks or the qx operator:

$return = `arguements here`;
$return = qx/arguements here/;
May 17 '07 #3
AdrianH
1,251 Expert 1GB
exec() - The exec() function executes a system command AND NEVER RETURNS

system() - The return value is the exit status of the program as returned by the wait() call.



If you want output returned (not exit status) you have to use backtiks or the qx operator:

$return = `arguements here`;
$return = qx/arguements here/;
That is true if you want the $return string to contain the text that will be returned by the execution. If you want the errorlevel, it will not work.

Oh, if you wish to get perl to execute a batch file and get it not to display anything, you would do this:

$return = system("cmd /c batchFile.bat > nul");

Note: by passing off to a batch file, this will not be 100% portable.


Adrian
May 17 '07 #4
KevinADC
4,059 Expert 2GB
That is true if you want the $return string to contain the text that will be returned by the execution....
Adrian
And that seems to be the case here. But maybe the OP will let us know what they are really trying to do: get output or exit status.
May 17 '07 #5
AdrianH
1,251 Expert 1GB
And that seems to be the case here. But maybe the OP will let us know what they are really trying to do: get output or exit status.
Yeah, I guess "the return" value is kinda ambigious.


Adrian
May 17 '07 #6

Post your reply

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

Similar topics

reply views Thread by Jeff Mason | last post: by
3 posts views Thread by Gunnar Liknes | last post: by
3 posts views Thread by Nikolay Petrov | last post: by
reply views Thread by YellowAndGreen | last post: by
reply views Thread by zermasroor | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.