Batch to Batch (Simple Question....I hope)

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
craving94509
Posts: 2
Joined: 05 Aug 2016 09:31

Batch to Batch (Simple Question....I hope)

#1 Post by craving94509 » 05 Aug 2016 09:53

I have 3 batch files:

C:\IBM\SMP\maximo\tools\maximo\updatedb.bat
C:\IBM\SMP\maximo\tools\maximo\configdb.bat
C:\IBM\SMP\maximo\deployment\buildmaximoear.bat

I am attempting to call these in the order listed above (waiting until the previous has completed).

I have tried adding the following to the end of the first .bat:

call "C:\IBM\SMP\maximo\tools\maximo\configdb.bat"
start "C:\IBM\SMP\maximo\tools\maximo\configdb.bat"

No matter what I do, at the end of the first .bat I get a command prompt back to:
C:\IBM\SMP\maximo\tools\maximo

I am hoping someone can help me. Ultimately I would like to have a single .bat that does the following:
__________________________
CD "C:\IBM\SMP\maximo\tools\maximo
CMD.EXE /K "C:\IBM\SMP\maximo\tools\maximo\updatedb.bat"

CD "C:\IBM\SMP\maximo\tools\maximo
CMD.EXE /K "C:\IBM\SMP\maximo\tools\maximo\configdb.bat"

CD "C:\IBM\SMP\maximo\deployment
CMD.EXE /K "C:\IBM\SMP\maximo\deployment\buildmaximoear.bat"

I should add that the batch files being called are all existing software batch files that I cannot modify.


Any help sure is appreciated.

aGerman
Expert
Posts: 4743
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Batch to Batch (Simple Question....I hope)

#2 Post by aGerman » 05 Aug 2016 11:17

I should add that the batch files being called are all existing software batch files that I cannot modify.

Nevertheless it would be very helpful if you have any chance to post their contents in order to even be able to understand the behavior. (Actually CALL should work ...)

Regards
aGerman

craving94509
Posts: 2
Joined: 05 Aug 2016 09:31

Re: Batch to Batch (Simple Question....I hope)

#3 Post by craving94509 » 05 Aug 2016 12:08

The syntax of updatedb.bat is:

Code: Select all

@ECHO OFF

REM
REM DO NO EDIT THIS FILE
REM AUTO Generated from updatedb.xml
REM
REM Script: updatedb
REM Converted updatedb.bat file.
REM
REM To get help, use --help
REM

SETLOCAL

set SCRIPT_DIR=%~dp0
set SCRIPT_NAME=updatedb.xml
set MAXIMO_SCRIPT_CP=%SCRIPT_DIR%\internal

if "%MAXIMO_JAVA%"=="" set MAXIMO_JAVA=%SCRIPT_DIR%\..\java\jre\bin\java.exe

@"%MAXIMO_JAVA%" -cp "%MAXIMO_SCRIPT_CP%" MaximoScript "%SCRIPT_DIR%%SCRIPT_NAME%" %*

exit /B %errorlevel%


Syntax for configdb.bat:

Code: Select all

@ECHO OFF

SETLOCAL

REM ConfigDB.bat --
REM      Runs psdi.configure.ConfigDB with -e (execute) parameter,
REM      followed by psdi.configure.RestoreFromBackup with -e (execute) parameter.
REM      The default database is defined in the maximo.properties file.
REM       The commandline parameters for overriding the defaults are listed below. 
REM      Also see javadocs for psdi.configure.ConfigDB and RestoreFromBackup.
REM
REM -a (db alias)     Database alias. If not specified, uses mxe.db.url property.
REM -d (logfile dir)     If using the -l parameter, will output logfile to the specified directory.
REM           If not specified, outputs to the MXServer log directory,
REM           which normaly is tools\maximo\log.
REM -e           Causes Sql to be executed.  (The commandline provided below includes the -e parameter.)
REM -f (filename)     Filename for properties file.  If not specified, uses maximo.properties.
REM           (Also see -k parameter for propfile directory.)
REM -k (propfile dir)     Directory for properties file.
REM           (Also see -f parameter for propfile filename.)
REM -l                      Outputs a detailed log file.
REM -o (filename)     If using the -l parameter, the filename for the logfile.
REM           If not specified, logfile is "ConfigDB" + timestamp + ".log".
REM           (Also see -d parameter for logfile directory.)
REM -p (password)     Password for database connection.
REM           If not specified, uses mxe.db.password property, or "maximo".
REM -r            Call RestoreFromBackup immediately after ConfigDB ends without error.
REM           Care should be taken when using this param, as there are occasions when
REM           the data in the temp tables (XX+tablename) must be modified before
REM           attempting the Restore.
REM -u (username)     Username for database connection.
REM           If not specified, uses mxe.db.user property, or "maximo".


call commonEnv.bat

REM set DB2DBDFT if run for DB2, uncomment the set command and use the correct value for database name.
SET DB2DBDFT=maxdb75

@..\java\jre\bin\java %MEMORY_ARGS% -classpath %MAXIMO_CLASSPATH%  psdi.configure.ConfigDB -l -e -r -k..\..\applications\maximo\properties  %1 %2 %3 %4 %5 %6

exit /B %errorlevel%


Syntax for buildmaximoear.cmd:

Code: Select all

@echo off

rem -----------------------------------------
rem The following are required for runnig ant
rem -----------------------------------------
set oldpath=%CLASSPATH%
set JAVA_HOME=.\..\tools\java\jre
rem set JAVA_HOME=C:\IBM\WebSphere\AppServer\java\jre
set ANT_HOME=.\..\tools\ant
set TOOLS_HOME=.\..\tools\maximo
set MAXIMO_HOME=.\..\applications\maximo

rem ------------------------------------------------------------
set BUILD_DIR=.\default
set EAR_FILENAME=maximo.ear

set MAXIMO_PROPERTIES=maximo.properties

set CLASSPATH=.;%MAXIMO_HOME%\businessobjects\classes;%MAXIMO_HOME%\lib\jdom.jar;%TOOLS_HOME%;%TOOLS_HOME%\classes
%JAVA_HOME%\bin\java  -classpath  %CLASSPATH% psdi.tools.MergeWSDefinition -k. -t.\..\applications\maximo\meaweb\webmodule\WEB-INF

%JAVA_HOME%\bin\java  -classpath %CLASSPATH%  psdi.tools.MaximoBuildEarTask -k.

IF ERRORLEVEL 1 GOTO resetclasspath

set ANT_OPTS=%ANT_OPTS% -Xmx1024M

call %ANT_HOME%\bin\ant  -buildfile .\buildmaximoear-build.xml -Dmaximo.builddir=%BUILD_DIR%  -Dmaximo.basedir=.\..\applications\maximo -Dmaximo.earfile=%EAR_FILENAME% -Dmaximo.properties=%MAXIMO_PROPERTIES%  %1

:resetclasspath
set CLASSPATH=%oldpath%
:End

aGerman
Expert
Posts: 4743
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Batch to Batch (Simple Question....I hope)

#4 Post by aGerman » 05 Aug 2016 12:58

At least for configdb and buildmaximoear the working directory seems to be important. Unfortunately I can't test it ...

Code: Select all

@echo off &setlocal
pushd "C:\IBM\SMP\maximo\tools\maximo"
call "updatedb.bat"
call "configdb.bat"
popd

pushd "C:\IBM\SMP\maximo\deployment"
call "buildmaximoear.cmd"
popd

Regards
aGerman

douglas.swehla
Posts: 75
Joined: 01 Jun 2016 09:25

Re: Batch to Batch (Simple Question....I hope)

#5 Post by douglas.swehla » 05 Aug 2016 14:35

craving94509 wrote:Ultimately I would like to have a single .bat that does the following:

Code: Select all

CD "C:\IBM\SMP\maximo\tools\maximo
CMD.EXE /K "C:\IBM\SMP\maximo\tools\maximo\updatedb.bat"

CD "C:\IBM\SMP\maximo\tools\maximo
CMD.EXE /K "C:\IBM\SMP\maximo\tools\maximo\configdb.bat"

CD "C:\IBM\SMP\maximo\deployment
CMD.EXE /K "C:\IBM\SMP\maximo\deployment\buildmaximoear.bat"



Try changing the above code to

Code: Select all

CALL "C:\IBM\SMP\maximo\tools\maximo\updatedb.bat"
CALL "C:\IBM\SMP\maximo\tools\maximo\configdb.bat"
CALL "C:\IBM\SMP\maximo\deployment\buildmaximoear.bat"


If that works, and you'd like to understand why, let me know, and I'll explain what's going on.

aGerman
Expert
Posts: 4743
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Batch to Batch (Simple Question....I hope)

#6 Post by aGerman » 05 Aug 2016 14:44

@ douglas.swehla

Have a look at the codes. There are relative pathes using . and .. that won't work without changing the working directories. That's the reason why I used pushd and popd.

Regards
aGerman

douglas.swehla
Posts: 75
Joined: 01 Jun 2016 09:25

Re: Batch to Batch (Simple Question....I hope)

#7 Post by douglas.swehla » 05 Aug 2016 15:20

@aGerman
That's what I get for not thoroughly reading the responses. You're quite right. I was just focused on fixing how to call the child scripts.

@craving94509
aGerman's answer is better than mine. Offer stands, if you want to understand why it didn't work before.

aGerman
Expert
Posts: 4743
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Batch to Batch (Simple Question....I hope)

#8 Post by aGerman » 05 Aug 2016 15:43

Don't worry. That happens to me all the time :lol:

Post Reply