Batch script executes twice

Hi,

Batch script gets executed without any error, but on execution some of the partial contents of the batch file gets appended at the end of the file which is currently in execution, hence the script tries to execute again for the second time , which should not happen.

How to get it solve?

Regards

Can you post your script here, to have a look to it ?

Hi,

cls
@echo off
echo.
echo ======================
echo EXECUTING POST SCRIPT 
echo ======================
echo.
SET /p username=Enter username:
echo.
SET /p password=Enter password:
echo.
SET /p path=Enter script path:
echo.
cd %oracle_home%\bin 
sqlplus "%username%/%password%" @%path%post_script.sql
SET username="a"
SET password="b"
SET tnsname="z"
cd \

First impressions.
These are system variables. Suggest you choose other names.

%username%
%path%

You may wish to append to %path% which would avoid changing to the Oracle bin directory. Inadvisible to overwrite %path% .

On the main problem, try opening the batch file and copy/paste to a new notepad file. Just in case you have an invisible up-arrow sequence somewhere in your script.

cls
@echo off
echo.
echo ======================
echo EXECUTING POST SCRIPT 
echo ======================
echo.

:username
SET /p username_=Enter username:
if not defined username_ (goto:username)
echo.

:pass
SET /p password=Enter password:
if not defined password (goto:pass)
echo.

:path
SET /p path_=Enter script path:
if not defined path_ (goto:path)
echo.
cd /d "%oracle_home%\bin" || (
	echo Error cambiando de directorio
	exit /b 1
	)
	
sqlplus "%username%/%password%" %path%post_script.sql
SET username="a"
SET password="b"
SET tnsname="z"
cd \

Hi

instead of cd, it is better to use popd and pushd.

move the declaration block to the begining of the script
SET username=""
SET password=""
SET tnsname=""

  1. Check if the script exist in the defined path, because the slash and duble slash can cause a problem.
    Batch files - IF statementsIF [NOT] EXIST filename command

  2. Add an exit commande in your sql script else you will remain connected.