Bug 53115 - catalina.bat run does not work if TEMP contains spaces
catalina.bat run does not work if TEMP contains spaces
Product: Tomcat 7
Classification: Unclassified
Component: Catalina
PC Windows XP
: P2 normal (vote)
: ---
Assigned To: Tomcat Developers Mailing List
Depends on:
  Show dependency tree
Reported: 2012-04-20 18:25 UTC by Eugene Petrenko
Modified: 2012-05-31 16:19 UTC (History)
0 users


Note You need to log in before you can comment on or make changes to this bug.
Description Eugene Petrenko 2012-04-20 18:25:41 UTC
Under clean Windows XP, under Administrator account. 
Default temp dir is like c:\Documents and Settings\Admin\Local Settings\TEMP

In catalina.bat there is a temp dir check:
if ""%TEMP%"" == """" goto mainEntry

Actually, this command does not work if TEMP contains spaces. 
The right line is:
if ""%TEMP%"" == """" goto mainEntry

i.e. to avoid double quoting
Comment 1 Konstantin Kolinko 2012-04-20 18:50:40 UTC
It is funny. I have WinXP. The "TEMP" variable is configured as

%USERPROFILE%\Local Settings\Temp

by default for the current user in the setting dialog (Win+Pause), but cmd shows

> echo %TEMP%

So the current catalina.bat already works for majority of Windows XP users, including me.
Comment 2 Eugene Petrenko 2012-04-22 15:00:41 UTC
There is a known issue under XP
Comment 3 Mark Thomas 2012-05-29 20:14:35 UTC
Given that %TEMP% may or may not contain spaces ad may or may not be quoted I simply do not see a way of getting this to work for all possible input. I'd be happy to be proved wrong though.
Comment 4 Sebb 2012-05-29 22:47:30 UTC
AFAICT it's not possible using IF because one cannot get past the syntax error that occurs when the quotes are mismatched.

However, I think I've found a solution.

Try the following:

REM The output of ECHO will be :: if TEMP is not defined
REM It's not possible for :: to be found within a valid TEMP variable
echo :%TEMP%: | find "::"
REM check for level 0, i.e. pattern found
if NOT ERRORLEVEL 1 goto mainEntry
Comment 5 Mark Thomas 2012-05-30 11:37:50 UTC
Neat trick. While that fixes the first problem, a similar approach can't be used for the following lines that use IF and %TEMP%.
Comment 6 Christopher Schultz 2012-05-30 14:16:52 UTC
We could detect the spaces in %TEMP% and issue an error message, stopping the startup script rather than ending up giving the user a bizarre error and letting them try to figure it out.
Comment 7 Eugene Petrenko 2012-05-30 14:21:53 UTC
Please remember the possible issue with Windows XP:

For some reason/bug path to %TEMP% may be not 8.3 style formatted. This simply makes catallina.bat fail and not start Tomcat. 

I faced exactly the same issue on my test Windows XP VM.
Comment 8 Mark Thomas 2012-05-31 07:42:54 UTC
There is no way I am aware of to fix this. See comment #3. Please do not re-open this issue unless you have a patch that actually fixes the issue.
Comment 9 Konstantin Kolinko 2012-05-31 10:34:01 UTC
(In reply to comment #3)

I think %TEMP% do not use quotes, like ones are not used in %PATH%.
The OS cares that %TEMP% do not contain spaces, and thus it would not be quoted.

You naturally do not use quotes when you configure values through GUI.
The syntax for SET command is less intuitive. For reference:

SET "TEMP=value"

[Offtopic] Regarding that thread on social.technet.microsoft.com I would say that
- The value of NtfsDisable8dot3NameCreation affects the time when a directory is created (in that case: when a profile is created), not when it is used. That is whether mkdir generates two names or just one.
- Setting TEMP to C:\Temp is a valid workaround for the issue.
Comment 10 Konstantin Kolinko 2012-05-31 14:11:37 UTC
Fixed in trunk and 7.0 by r1344725 and r1344732 and will be in 7.0.28.

Note that
- The issue only affects the "run" command. All other command skip that code.
- The issue affects 7.0.x only. Earlier versions do not have that code in catalina.bat.
Comment 11 Sebb 2012-05-31 14:49:28 UTC
(In reply to comment #9)
> (In reply to comment #3)

> You naturally do not use quotes when you configure values through GUI.
> The syntax for SET command is less intuitive. For reference:
> SET "TEMP=value"

On WinXP, the command:
SET TEMP1=a b c
is the same as
SET "TEMP2=a b c"

Neither adds quotes to the value of X.
However, the following command does add quotes:

SET TEMP3="a b c"

The result of the above is:

TEMP1=a b c
TEMP2=a b c
TEMP3="a b c"
Comment 12 Sebb 2012-05-31 16:19:00 UTC
AFAICT, the TEMP directory is being used for two purposes:

1) for a file containing "Y"
2) as a marker to stop a recursive call of catalina.bat

The first use is trivial to eliminate; just ship Tomcat with a suitable file

The second use can also be eliminated.

If you can assume that Command Extensions are enabled, the following will work:

rem Suppress Terminate batch job on CTRL+C
if not ""%1"" == ""run"" goto mainEntry
if ""%TEMP%"" == """" goto mainEntry
rem Assumes Y.DAT exists
call :mainEntry %* <Y.DAT
rem Use provided errorlevel
exit /B %RETVAL%

If not, then rather than using a marker file in TEMP, you can use a SET variable:

rem Suppress Terminate batch job on CTRL+C
if not ""%1"" == ""run"" goto mainEntry
if ""%TEMP%"" == """" goto mainEntry
if ""%_RECURSE_%"" == ""TrUe"" goto mainEntry
set _RECURSE_=TrUe
call "%~f0" %* <Y.DAT
rem Use provided errorlevel
set _RECURSE_=
exit /B %RETVAL%

Yet another possibility is to split catalina.bat into two so the mainEntry code is in a separate file. This solves the recursive call issue.