It's been a while since my last visit, but i've been busy (as always) and stumbeled upon a problem i can't tackle.
I need to verify a user-given path that leads to Javaw.exe.
The code i have right now looks like this:
Code: Select all
@ECHO OFF
MODE CON COLS=80 LINES=25
SETLOCAL EnableExtensions EnableDelayedExpansion
TITLE Path ^& Application ERRORLEVEL-tester v0.1 (20092012-0025)
IF NOT EXIST PathAppTest (
CD.>PathAppTest 2>NUL
)
:START
CLS
echo.
SET /P TESTER=Te testen pad/programma:
IF DEFINED TESTER (
ECHO !TESTER!>PathAppTest 2>NUL
goto CHECK
)
IF "!TESTER!"=="" (
CD.
IF EXIST PathAppTest (SET /P TESTER=<PathAppTest) ELSE (goto START)
)
:CHECK
IF !TESTER:~-1!==\ (
SET TESTER=!TESTER:~0,-1!
goto CHECK
)
echo.
ECHO Pad/programma om te testen: "!TESTER!"
echo.
"!TESTER!"
echo.
ECHO ERRORLEVEL %ERRORLEVEL%
echo.
PAUSE>NUL|SET /P =
SET TESTER=
:: RESET ERRORLEVEL
CD.
goto START
It works most of the time, but whenever i enter a colon as path, it shows ERRORLEVEL 0 (which i find awkward).
Even when typing a colon in the DOS promt it shows nothing but a new prompt:
Code: Select all
C:\Users\admin>:\javaw.exe & ECHO ERRORLEVEL %ERRORLEVEL%
C:\Users\admin>
A semi-colon gives a whole different result (disappearing semi-colon):
Code: Select all
C:\Users\admin>;\javaw.exe & ECHO ERRORLEVEL %ERRORLEVEL%
\javaw.exe wordt niet herkend als een interne
of externe opdracht, programma of batchbestand.
ERRORLEVEL 3
Other examples:
Code: Select all
C:\Users\admin>javaw.exe & ECHO %ERRORLEVEL%
javaw.exe wordt niet herkend als een interne
of externe opdracht, programma of batchbestand.
ERRORLEVEL 9009
C:\Users\admin>\\javaw.exe & ECHO ERRORLEVEL %ERRORLEVEL%
De syntaxis van de bestandsnaam, mapnaam of volumenaam is onjuist.
ERRORLEVEL 123
C:\Users\admin>/\javaw.exe & ECHO ERRORLEVEL %ERRORLEVEL%
De syntaxis van de bestandsnaam, mapnaam of volumenaam is onjuist.
ERRORLEVEL 123
C:\Users\admin>'\javaw.exe & ECHO ERRORLEVEL %ERRORLEVEL%
De syntaxis van de bestandsnaam, mapnaam of volumenaam is onjuist.
ERRORLEVEL 3
(most characters i tested showed an ERRORLEVEL 3)
My question: Is there a way to somehow work around this problem, as the code is a pretty crucial part of my script (verify/test a user-given java-path and use the path on a successful test).
Thank you for reading/thinking along with me