Control-M job not ending after .bat finishes - ms-access

I have a .bat file that maps a network drive, runs an MS Access program then deletes the mapped drive and exits. When I run it through Control-M the .bat runs and finishes but the job in Control-M never ends. I have tried multiple things to end the file to send Control-M an exit code but nothing seems to be working. Below is the code:
#echo off
net use w: [path]
"C:\Program Files\Microsoft Office\OFFICE11\MSACCESS.EXE" "Y:\MSAccess.mdb"
net use w: /delete
After this code I have tried the following commands:
exit
_exit 0
timeout /T 10
No matter what I try Control-M never seems to know that the job has finished. The sysout from Control-M also does not show any kind of exit code being sent back.

Control-M is probably waiting for all the processes started under it to exit before exiting the job itself. In your case, MSACCESS is still running when the end of the BAT is reached, so it prevents Control-M job to finish.
If you have your BAT to wait for MSACCESS to finish,
net use w: [path]
start /b /wait "" "C:\Program Files\Microsoft Office\OFFICE11\MSACCESS.EXE" "Y:\MSAccess.mdb"
net use w: /delete
this might alleviate (at least stetically) your problem

After some more testing and investigation the issue was happening earlier in the .bat. The MS Access database was never being opened and run. Therefore since it was never starting it was never ending or sending an error code. I am researching why the MS Access database was not running now, which may lead to another question.

I had the same problem. I resolved my problem by adding the following at the end of the bat file:
exit /b %errorlevel%

For Windows batch scrips, add exit /b %errorlevel% at the end of file. This will help to find script has processed properly and control job will end/endnotok.

Related

Need to capture the Exit code returned from WinSCP using Execute process task [duplicate]

This question already has answers here:
If there is an error, how can I exit from SSIS package
(1 answer)
Fail SSIS task when the mask to select files to be uploaded to FTP server using WinSCP matches no files
(1 answer)
Closed 3 years ago.
I have a SSIS package that executes the WinSCP.exe via execute process task and download the set of files to some common folder location.
Files names are:
Text1.csv
Test2.csv
and so on..
After that I am running another set of Execute process tasks which will use the C:\Windows\System32\cmd.exe which start copying downloaded files to different respective locations.
Below is my command line arguments to first download the files at some common location:
/log=G:\USER_DATA\USER_USER_SYNC\SFTP_LOG\user_sync_winscp.log /command "open sftp://bisftp:*UFVy2u6jnJ]#hU0Zer5AjvDU4#K3m#stransfer.host.com/ -hostkey=""ssh-rsa 2048 9b:63:5e:c4:26:bb:35:0d:49:e6:74:5e:5a:48:c0:8a""" "cd /DATA" "get -filemask=">=today" Test1.csv Test2.csv G:\USER_DATA\USER_USER_SYNC\Download\" "exit"
Below are my command line arguments to copy the files to different locations:
/C copy /b G:\USER_DATA\USER_USER_SYNC\Download\Test1.csv G:\USER_DATA\USER_USER_SYNC\Testing1
/C copy /b G:\USER_DATA\USER_USER_SYNC\Download\Test1.csv G:\USER_DATA\USER_USER_SYNC\Testing2
I have few questions here.
Since I am using filemask to download the latest updated files only.
If first Execute process task run successfully then it will set the exit code returned as '0' and then next Execute process task gets executed to copy the files to different locations.
Everything runs fine till this end.
However there can be a case when first execute task is not able to download the files to common folder location.
Reasons of failure could be that other party has not put the latest files on SFTP server and due to date mismatch, it was not able to download the files in first place or could be some other network issues as well.
So it throws an exception that like "The process exit code was "1" while the expected was "0"." due to when my next subsequent execute process task run and it's getting failed as it has nothing to copy or move.
Can we capture the exit code returned to some variable, so that we can use it further in some expression to decide whether to execute another task or not?
Also I am using different execute process task to copy the files. Can we combine separate copy steps into one and use one Execute process task?

SSIS - EXECUTE PROCESS TASK The process exit code was "16" while the expected was "0"

IN The SSIS package I am getting execute process task error; exit code was 16 expected was 0 I am using robocopy however when I use robcopy from command prompt it successfully copy my zip files from one folder to another folder.
Please help me in resolving this issue.
Thanks
A return code of 16 suggest you have permissions issues. If you are running your package via SSDT/BIDS, make sure you are running it as an administrator.
To open BIDS/SSDT as an administrator, right click on the shortcut and hit run as administrator, then open your solution.
If you are running it via Sql server agent job make sure the user/proxy account you are using has required access/permission.

How to fix exit code issue while using WinSCP for SFTP from within SSIS package?

I am using SSIS 2005 to do some SFTPtasks using WinSCP. I googled about the error but couldn't make it work. I got this error:
[Execute Process Task] Error: In Executing "C:\Program Files\WinSCP\WinSCP.exe" "-script=C:\Documents and Settings\nian_z\Desktop\temp\SSISMovingSOA\removeSOA8.txt" at "C:\Program Files\WinSCP", The process exit code was "1" while the expected was "0".
Here is my WinSCP script that I use:
option batch abort
option confirm off
#open sftp://user:password#server:22
#cd /m/vo/Cont/fileftp
get OrderOutbound*
close
exit
For above script, I even tried leaving only one statement at a time, but still got error.
Here is the setup of the execute process task.
This is not an answer but an attempt to help you find a solution to your problem.
Try this:
Try the following steps to find out if your script is actually working outside of SSIS or not.
Click Windows Start and click Run...
Type cmd to open Command Prompt.
On the command prompt window, type the following command at the prompt to switch to the WinSCP installation directory. I have the WinSCP installed in the following directory. Change the path according to your environment settings.
cd "C:\Program Files (x86)\WinSCP"
If your WinSCP script file removeSOA8.txt is located in the path C:\Documents and Settings\userid\Desktop\temp\SSISMovingSOA\ with spaces, then type the following command by enclosing the script path in double quotes to run the script and also use the /log option to capture all the status messages.
WinSCP.exe "/script=C:\Documents and Settings\userid\Desktop\temp\SSISMovingSOA\removeSOA8.txt" /log=C:\temp\WinSCP_log.txt
After the script executes, your will find that a log file named WinSCP_log.txt will be created in the path C:\temp. Read through the file to identify if there are any error messages.
Attempt to run FTP in SSIS:
I tried downloading a file from FTP using WinSCP with the following script:
option batch abort
option confirm off
open ftp://myuserid:mypassword#ftp.myftpsite.com:21 -passive=on
cd /root/somefolder/
option transfer binary
get SomeFileOnFTP.txt c:\temp\
close
exit
Here are the settings how I have configured the Execute Process Task within the SSIS package.
The process ran successfully in BIDS.
Hope that gives you an idea.
If you are running the script from SQL Server job agent then mostly you will get this exit error.
Scenario: In my case I faced when i m trying to download a file from sFTP server.
Solution :
Step 1 - Create a batch file
#echo off
CD "C:\Program Files (x86)\WinSCP"
winscp.com /ini=nul /script=C:\path\download_script_pm.txt
Exit
Note: When calling using SQL Server Job agent make sure to NULL out the “ini” configuration else it will throw up this error
Step2 – create a txt file (winscp script)
option echo on
option batch on
option confirm off
open sftp://user:password#sftp.xxxx.com/ -hostkey="ssh-edXXXX-xx-xx-xx-xx-xx-xx-xx-xx-xx-xx-xx-xx-xx-xx-xx-xx"
option confirm off
get -filemask=">=1D" /sftp_Path/File_Name_.csv
C:\local_path_for_downloaded_file\"
exit
Note: make sure to use hostkey. To obtain host key you need to do the following :
1. Open winscp app tool and login to the server
Click Session -> Generate Session / URL code option
Check SSH Host key and copy the finger print value and use in the winscp hostkey value
Earlier I was getting the same error but now is working fine for me.
SSIS Execute Process Task :
Executable - C:\SSIS\SSIS_2008_Projects\HRIS_RepomanFusion_Load\WinSCP\WinSCP.com
Arguments - "/script=wscpBatchTest.txt" /log=C:\SSIS\SSIS_2008_Projects\FTP_Load\WinSCP\WinSCP_log.txt
Working Directory - C:\SSIS\SSIS_2008_Projects\HRIS_RepomanFusion_Load\WinSCP
Here is the WinSCP script that I use: wscpBatchTest.txt
option batch
option confirm off
open sftp://username:password#ftp.test.com
option transfer binary
cd /home/SAFAA
get employeedetails.csv C:\SSIS\SSIS_2008_Projects\SAFAA\InputDirectory\
close
exit

Hudson - Windows Batch Script -Build

i am running build via windows batch script. if build fails it not sending mail to developers, who broke the build.
can you help me.
Regards
Akilan
Make your batch script set an exit code (Error level) signalling success or failure of the batch script. This should indicate to hudson that the batch file failed. Exiting with a zero error level indicates success, and nonzero indicates failure. If your batch file calls other applications (compiler etc.) you might be able to use their respective exit codes to set the error level of your batch file.
For example
#echo off
compiler.exe sourcefile.abc
exit /B %ERRORLEVEL%
The last line would return the exit code of compiler.exe as the return code of your batch file.
If you have multiple executions in your batch file, you can test the errorlevel between each exceution with IF ERRORLEVEL and fail whenever you detect a nonzero errorlevel.
Also, remember to test the email sending functionality using the test tool found where you configure smtp server etc. inside the hudson/jenkins config.

CMD runs EXE, launches HTML, wait until close and run final EXE

would like have BAT file that runs set-keys.EXE, launches default.html, and then when user closes html, run set-keys-back.EXE. (they are all in the same directory together). This might be run from a CD, so I might not have ability to write a flag file and then wait to see if it is deleted in order to continue. Have already tried START /WAIT but have seen that WAIT won't actually wait for GUI 32-bit applications. Have considered one batch file calling another one, still no luck. Would prefer not to have PAUSE and user have to come back to CMD just to hit a key - seems clunky. When they close out of HTML, I execute top.window.close(). would be nice if I could put some other code after that, but I think once the window is closed it's closed - no more processing. have not been able to get WShell execute to run. HTML status bar just says error on page - no info. Would love to hear your thoughts...
Update 2: I just figured out that you can launch IE directly without having to use the start command:
#echo off
rem You can use %SCRIPTDIR% to refer to the file to load, if you like
rem Note that %SCRIPTDIR% will contain a trailing slash!
set SCRIPTDIR=%~dp0
echo Testing this script...
C:\PROGRA~1\INTERN~1\iexplore.exe %SCRIPTDIR%foo.html
echo Continuing the script...
This example works for me (Windows XP 32-bit), and waits for me to close the browser window to continue.
Update: Here's an updated code block that launches Internet Explorer. Note that I use the short path to the iexplore.exe executable, and I specify the full path to the file to load:
#echo off
echo Testing this script...
start /wait /min cmd /C "C:\PROGRA~1\INTERN~1\iexplore.exe C:\foo.html"
echo Continuing the script...
Initial Answer: You mentioned trying the start /wait command, but how did you explicitly write it? The following batch script example works for me in Windows 7 x64:
#echo off
echo Testing this script...
start /wait /min cmd /C "%windir%\system32\notepad.exe foo.html"
echo Continuing the script...
In this example, the script does not continue execution until the user closes the Notepad application. The only downside here is that an extra command window pops up, but by using the /min parameter, we can start it minimized.