469,328 Members | 1,251 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,328 developers. It's quick & easy.

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 9076
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 zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Purva khokhar | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.