0

I made a batch script that iterates recursively through all the .sql files under a directory. My problem is that i can echo all the files treated correctly with this version :

 @for /r "%PWD%\06-Instalaciones" %%a in (*.sql) do (IF "C:%%~pa" NEQ "%PWD%06-Instalaciones\ProximaInstalacion\" echo %%~fa )

But i cant seem to sucessfully call SqlPlus instead of the echo, for every sql file treated :

@for /r "%PWD%\06-Instalaciones" %%a in (*.sql) do (IF "C:%%~pa" NEQ "%PWD%06-Instalaciones\ProximaInstalacion\" %ORACLE_HOME%/bin/sqlplus -L -S FOO/BAR@%sid% @%%~fa)

I get the following error : "(HOST was unexpected at this time.".

Thank you.

6
  • Try writing echo before %ORACLE_HOME%/bin/..., to see what the command expands to, and if there is a parameter with spaces that needs quoting. Commented Nov 19, 2013 at 12:23
  • I tried what u said and the %%~fa aint expanding. If need to wrap the whole SqlPlus call in quotes for it to work, but then SqlPlus doesnt execute. Commented Nov 19, 2013 at 12:53
  • Try using another letter, for example %%G, since %~fa already has the meaning filename + attributes. Commented Nov 19, 2013 at 13:03
  • I can't expand %%G,if i repeat the echoing and quoting process i get %G. Commented Nov 19, 2013 at 13:10
  • I tried with %%f : @for /r "%PWD%\06-Instalaciones" %%f in (*.sql) do (IF "C:%%~pf" NEQ "%PWD%06-Instalaciones\ProximaInstalacion\" %ORACLE_HOME%/bin/sqlplus -L -S FOO/BAR@%sid% @%%~f >> log.txt) Commented Nov 19, 2013 at 13:53

1 Answer 1

1

Thanks to angus for pointing out my error. I had a space in one of my variables!!! Particularly in %sid%. I'll leave here my code in case someone needs it :

@echo off
@SET PWD=%~dp0
@SET sid=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=xxx.xxx.xxx.xxx)(PORT=1521))(CONNECT_DATA=(SERVER=dedicated)(SID=xxxxx))) 
@for /r "%PWD%\06-Instalaciones" %%f in (*.sql) do (IF "C:%%~pf" NEQ "%PWD%06-Instalaciones\ProximaInstalacion\" %ORACLE_HOME%/bin/sqlplus -L -S FOO/BAR@"%sid%" @%%~f >> log.txt)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.