If exist file gives unusual error message

Microsoft Windows 7 ultimate oem 64bit
September 10, 2010 at 21:58:01
Specs: Windows 7
My problem is this:

I have developed a .bat menu system for signing zips and other things for android devices, using multiple linked .bats. Initially, i need to check for Java to be installed.
My Main bat file (the main menu) looks like this (just up to the spot of the problem, with a few irrelevant lines taken out):

@echo off

Set Path=%path%;"%CD%\tools\for_path"
Set mainCD=%CD%

:: Checks environment on startup
:initialize
Call "%CD%\tools\executables\initialize.bat"
_____________________________________

Right there, it calls for "initialize.bat", which looks like this (just the part that has the problem:


Echo --------------------
Echo Checking Java
Echo --------------------
Call "%CD%\tools\executables\javaCheck.bat"
if %ERRORLEVEL% == 1 (
exit /b 1
)

_____________________________
this calls "javaCheck.bat", and I have confirmed that it calls the bat by echoing test then a pause on the first 2 lines in javaCheck.bat. The problem is here (the first few lines of javaCheck.bat):

if exist "%programfiles%\Java\jre6\bin\java.exe" (
Echo Java 1.6
Set Path=%path%;"%programfiles%\Java\jre6\bin"
exit /b
)
if exist "%programfiles(x86)%\Java\jre6\bin\java.exe" (
Echo Java 1.6
Set Path=%path%;"%programfiles(x86)%\Java\jre6\bin"
exit /b
)

When it gets to the if exist statement (even though Java.exe DOES exist) it does not do anything in the brackets, not even if I place an "Echo test", for instance. I get an unusual error. And the error was different on another computer.

On one computer I get
\ATI was unexpected at this time.

and on another I got
\Common was unexpected at this time.

Now this seems to me like it is reading a Different folder in %programfiles%/%programfiles(x86)%, such as "ATI Technologies", or "Common Files" (since those exist in there).

I have done a search in ALL of my linked .bats and there are no references to an ATI, or Common.

This has only happened on x64 computers. My bats work perfectly on Windows 7 x86

When I make a separate bat file and run it with the same commands, it runs fine... is there a limit to how many bats you can call inside of one another and still get accurate results?

Any help would be GREATLY appreciated. This is the last bug I need to sort out.


EDIT:
Even when I edit initialize.bat to this:
cls
Echo.
Echo Checking Environment...
Echo.
Echo.


Echo --------------------
Echo Checking Java
Echo --------------------
if exist "%programfiles%\Java\jre6\bin\java.exe" (
Echo Java 1.6
Set Path=%path%;"%programfiles%\Java\jre6\bin\"
goto good
)
if exist "%programfiles(x86)%\Java\jre6\bin\java.exe" (
Echo Java 1.6
Set Path=%path%;"%programfiles(x86)%\Java\jre6\bin\"
goto good
) else ( blah)

it STILL gives me the \ATI was unexpected error...

and I tested
Echo %programfiles(x86)%\Java\jre6\bin\java.exe

and it did return the full real path...

This is confusing..

Thanks for your help :)


See More: If exist file gives unusual error message

Report •


#1
September 29, 2010 at 22:41:23
Well I'm not sure what the problem is, but there is a way to work around it. Instead of using:

if exist "%programfiles%\Java\jre6\bin\java.exe" (
Echo Java 1.6
...command...
)

Try using:

if exist "%programfiles%\Java\jre6\bin\java.exe" GOTO exists

<other code here>

:exists
echo Java 1.6
set Path=%path%;"%programfiles(x86)%\Java\jre6\bin"
exit /b

That worked for me in a similar test :-)


Report •
Related Solutions


Ask Question