473,581 Members | 2,314 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

get return value from batch

4 New Member
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("te st.bat");

$val=exec “test.bat”;

Thanks
Ronen
May 17 '07 #1
5 9347
AdrianH
1,251 Recognized Expert Top Contributor
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("te st.bat");

$val=exec “test.bat”;

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

Adrian
May 17 '07 #2
KevinADC
4,059 Recognized Expert Specialist
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 Recognized Expert Top Contributor
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 Recognized Expert Specialist
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 Recognized Expert Top Contributor
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

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

Similar topics

2
9914
by: brad | last post by:
I am new to perl and would like to know how to check the return values of a perl program in a batch file. how can I save the return value of the perl program and use it to make decisions as to what I should do next in the batch file?
0
1690
by: Jeff Mason | last post by:
Consider the following (questionable, to be sure, but syntactally legal) stored procedure (using the Northwind database): Create Procedure Test As Return (Select Count(*) From Orders) Select * From Orders; If you execute this SP in QA via:
3
14042
by: Ajay Garg | last post by:
I am running the following OSQL command and capturing the return code for the error .Whenver i have an error like server not exists or uable to login I get a return code of 1 for the %ERRORLEVEL%.However whenever I have an errorof a wrong dbcompatibility error the retun code id 1 even though sql returns an iformation message from OSQL that...
3
2204
by: Gunnar Liknes | last post by:
Hi, Is it possible to make a stored procedure or function to generate a return value? I have a stored procedure which inserts a new row in a table. I would like that proceudre to return the ID (autogenerated field) of the row after it has inserted it.
0
379
by: DBQueen | last post by:
I am developing an application for a Pathology Lab. There are Batches (BatchID) which contain multiple Samples (SampleID), and there can be multiple tests run from the same Sample, thus there can be multiple records with the same SampleID. The Basic Data for the samples is entered when the batch is set up initially. There are also 3...
33
7604
by: Steven Taylor | last post by:
Hope someone can help. This is half an Access question. The half I'm using is Access Xp as a backend data file. I'm using ODBC to connect to the data file. All commands are via SQL type statements (SELECT, UPDATE & INSERT INTO). (I'm using/trialling Realbasic as a frontend). After inserting a record (row) into a table using "INSERT...
3
1411
by: Nikolay Petrov | last post by:
how to return code from my app? like in ol' dos progs i need to call my app from a batch file and do some things based on the return code tnx
3
2046
by: Stephen | last post by:
Hi, I have a table consists which cosists of batch numbers, and assosiated dates and times..ie the columns are batch, date and time. The data within the table is not in any particular order. With a report, I need to calculate and display the difference in date / times between like batch numbers, ie displaying batch number, start date &...
1
2133
by: hameeduddinasim | last post by:
Hi guy's I have a batch file which return's me the string output I success to execute the batch file from C#.Net, but unable to capture return value, I need that return string to be use in rest of my application System.Diagnostics.Process proc = new System.Diagnostics.Process(); proc.EnableRaisingEvents = false;
0
7789
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8144
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8301
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6551
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5361
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3803
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3820
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1400
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.