Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calling a DB2 command window from a Windows shell script

Status
Not open for further replies.

lu1lu1

Programmer
Jan 28, 2004
2
DE
Hi,
I've created a windows batch file and want to use it to execute a few DB2 commands. I've read the documentation and it told me that I must call the db2cmd.exe followed by db2 command I want to execute. Here is an example of a batch file: myFile.bat

@echo off
db2cmd -c -w -i db2 connect to XXXX user XXXXD using XXXX

II copy this batch file to the \SQLLIB\BIN file where the db2cmd.exe file is located, everything works as decribed but if the batch file is located in any other directory, it doesn't work. Calling the db2cmd.exe creates a DB2 command line processor window but with the directory path set to the path where it was called. eg

c:\Testdir\db2cmd.exe
....creates a DB2 CLP window with the dir set to c:\Testdir and the db2 commands will not execute unless the path is set to the SQLLIB\BIN directory. I tried adding a cd c:\...SQLLIB\BIN as the next line in my batch file but it still doesn't work.

It works if I call the batch file like this:

c:\Testdir\db2cmd.exe -c -w -i myFile.bat

...where the bat file has for example:

@echo
db2 connect to XXXX user XXXXD using XXXX

It's a work around but I'd prefer to just call the bat file and do everthing from inside. I read the DB2 UDB scripting on windows and that says that it's possible but it doesn't state if it's possible from chosen directories. Can anyone throw some light on this as I'd be interested to know how to get it to work.
 
What we do is fully qualify the path to the DB2 command-line processor, as well as fully qualify the path to our scripts (that contain the db2 connect ....). For example, to setup Windows scheduler scheduled task that runs a database backup (via a batch file) you can use:

D:\SQLLIB\BIN\db2cmd.exe /c /w /i "E:\scripts\backup.bat > E:\script_output\backup.out"

Where you can redirect the output of your batch file to some other file for reading later.

Hope that this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top