Abhishek kumar
asked on
Reg: How to use batch script output value in vbscript
Hi All,
i have Below Batch script command
@echo off
set VAR=%errorlevel%
D:\SchedTasks\IFRS-Transfe r\psftp.exe IFRS@DM3CXJ -pw XXXX -b IFRSTransfer.txt
echo %VAR%
exit /b %ERRORLEVEL%
And i wanted to use VAR value of this batch script in VBscript.
so kindly please tell me how can i use .
Thanks,
Abhishek
i have Below Batch script command
@echo off
set VAR=%errorlevel%
D:\SchedTasks\IFRS-Transfe
echo %VAR%
exit /b %ERRORLEVEL%
And i wanted to use VAR value of this batch script in VBscript.
so kindly please tell me how can i use .
Thanks,
Abhishek
Why? VAR contains the error level at batch start, which is 0. This doesn''t have any "value". The exit code is important, and that is what you automatically get from the Shell.Run method calling the batch file.
You're aware that %VAR% contains the errorlevel before the psftp.exe call?
Anyway, assuming you want to call the VBScript from this batch (or are you calling the batch from VBScript? that would be rather cumbersome, because you might just as well run the psftp.exe directly from VBScript), you just pass it as command line argument:
VBS:
Anyway, assuming you want to call the VBScript from this batch (or are you calling the batch from VBScript? that would be rather cumbersome, because you might just as well run the psftp.exe directly from VBScript), you just pass it as command line argument:
VBS:
VAR = WScript.Arguments(0)
Wscript.Echo "VAR is " & VAR
Batch:@echo off
set VAR=%errorlevel%
D:\SchedTasks\IFRS-Transfer\psftp.exe IFRS@DM3CXJ -pw XXXX -b IFRSTransfer.txt
echo %VAR%
cscript.exe //nologo "C:\Temp\Whatever.vbs" %VAR%
exit /b %ERRORLEVEL%
ASKER
Hi,
Actually i wanted to use the psftp.exe exit code value in vb script for sending the mail whether file transfer is successful or Failed.
Here i am calling Batch script command inside VB Script.
So please help me how can i do this .
Thanks,
Abhishek
Actually i wanted to use the psftp.exe exit code value in vb script for sending the mail whether file transfer is successful or Failed.
Here i am calling Batch script command inside VB Script.
So please help me how can i do this .
Thanks,
Abhishek
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you so much :)
its working as expected :)
its working as expected :)
Hi oBdA,
For below Script
@echo off
pscp.exe -i seom.ppk D:\Informatica\9.6.1\serve r\infa_sha red\TgtFil es\IFRS\Cu stomer\zrr em19cus* seom@sapcir-qa.intranet.z. ca:/infile s
exit /b %ERRORLEVEL%
its not returning the Exitcode value and also the batch command is running for longer time
so kindly please help me how can i use exit code value of this batch script in VBscript.
Thanks,
Abhishek
For below Script
@echo off
pscp.exe -i seom.ppk D:\Informatica\9.6.1\serve
exit /b %ERRORLEVEL%
its not returning the Exitcode value and also the batch command is running for longer time
so kindly please help me how can i use exit code value of this batch script in VBscript.
Thanks,
Abhishek
That's not an issue with the batch file itself.
If this batch runs a long time, then it's the pscp.exe command that's taking long; the batch script will just wait until it's done.
Once pscp.exe is done, the errorlevel returned by it will be passed to the calling program just like with psftp.exe (that is, if pscp.exe returns an errorlevel to begin with - not all programs do).
If this batch runs a long time, then it's the pscp.exe command that's taking long; the batch script will just wait until it's done.
Once pscp.exe is done, the errorlevel returned by it will be passed to the calling program just like with psftp.exe (that is, if pscp.exe returns an errorlevel to begin with - not all programs do).
Okay Sir.
Thank you so much :)
Thank you so much :)
Solution provided
Example (gets the NUMBER_OF_PROCESSORS variable, this is taken from
Windows Script Host documentation):
Open in new window
Refer to
https://msdn.microsoft.com/en-us/library/at5ydy31(v=vs.84).aspx
https://msdn.microsoft.com/en-us/library/6s7w15a0(v=vs.84).aspx