Invalid character in file . bat

Asked

Viewed 2,019 times

1

Sirs !

I have a . bat file that I use to start Apache Tomcat from my application in debug mode. But while running this file on CMD, the first thing displayed is the following message:

'' is not recognized as an internal command or external, a operable program or a batch file.

I stress that after this, the script works normally, but I would like to know if anyone has ever been through something similar or knows any solution. I had tried to do the same, but the error persists.

Below is the contents of the file:

@echo off

echo.

rd /s /q C:\tomcat\work\
rd /s /q C:\tomcat\conf\Catalina\
del /s /q C:\tomcat\logs\*
del /s /q C:\tomcat\temp\*
del /s /q C:\tomcat\webapps\sa\WEB-INF\web.xml.template
del /s /q C:\tomcat\webapps\sa\META-INF\context.xml.template

echo.

set CATALINA_HOME=C:\tomcat
set CATALINA_BASE=C:\tomcat
set JAVA_HOME=C:\java\jdk7
set INSTANCE=C:\instance

set CATALINA_OPTS=-Xms256m -Xmx512m -XX:MaxPermSize=256m 

set CATALINA_OPTS=%CATALINA_OPTS% -Dfile.encoding=UTF-8
set CATALINA_OPTS=%CATALINA_OPTS% -Djava.awt.headless=false
set CATALINA_OPTS=%CATALINA_OPTS% -Dcom.sun.management.jmxremote
set CATALINA_OPTS=%CATALINA_OPTS% -Dcom.sun.management.jmxremote.port=9014
set CATALINA_OPTS=%CATALINA_OPTS% -Dcom.sun.management.jmxremote.ssl=false
set CATALINA_OPTS=%CATALINA_OPTS% -Dcom.sun.management.jmxremote.authenticate=false
set CATALINA_OPTS=%CATALINA_OPTS% -Dorg.apache.catalina.loader.WebappClassLoader.ENABLE_CLEAR_REFERENCES=false
set CATALINA_OPTS=%CATALINA_OPTS% -Duser.timezone=America/Sao_Paulo
set CATALINA_OPTS=%CATALINA_OPTS% -Duser.language=pt
set CATALINA_OPTS=%CATALINA_OPTS% -Duser.region=BR
set CATALINA_OPTS=%CATALINA_OPTS% -Dsun.java2d.noddraw=true
set CATALINA_OPTS=%CATALINA_OPTS% -Dsun.java2d.d3d=false
set CATALINA_OPTS=%CATALINA_OPTS% -Xdebug 
set CATALINA_OPTS=%CATALINA_OPTS% -Xrunjdwp:transport=dt_socket,address=8990,server=y,suspend=n

%CATALINA_HOME%\bin\startup.bat
  • Are you sure this is the bat and not the startup.bat? If you copy the contents of that bat such as this one here and save in another bat file and runs it error also occurs?

  • Hi Reginaldo ! The problem is in this . bat probably because the error is displayed on the screen before the first action of the script and the startup call is the last step. I stress that yes, I tried to recreate the . bat as you suggest and the error persisted. Thank you !

  • Save the file with ANSI pattern, and test.

2 answers

4

Your file was possibly saved with UTF-8 WITH BOM (GOOD being the abbreviation of BYTE ORDER MARK) in the notepad, ie at the top of the document .bat or any kind of document, when it is saved with UTF-8 GOOD a character called is added byte-order mark, which has already been cited in some questions here on the site, more details on the GOOD in utf-8 and others as utf-32 in:

Basically your . bat thinks this character called byte-order mark is a command, in this case the Unicode character U+FEFF is printed as ´╗┐, o . bat then looks for a program with such a name, which probably does not exist, thus causing the unrecognized command or program error.

I created an example saving in UTF-8 via Windows Notepad:

@echo off

echo Oi

pause

In case I left a line before the @echo off and just while running the same error occurred:

erro

See that it is the same character ´╗┐


If you want to use UTF-8 you must save with UTF-8 without BOM or use ANSI (or any compatible format), it will depend on the need.

If you still want to use UTF-8 you should make use of a more advanced program, such as Notepad++ that can be downloaded at:

Open your . bat on it and save so:

utf8 sem bom

If utf-8 is not necessary for you in the windows own notepad select Save as... and select ANSI:

ANSI

1

Maybe your problem is not in batch, but in the character page used on the system by the prompt/cli interface, I suggest checking the key settings:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Nls\CodePage
OEMCP="850"

Check if it shows anything other than 850 or 1252, if there is another value, just change 850, or 1252

To check on the command line, use:

reg query "HKLM\SYSTEM\CurrentControlSet\Control\Nls\CodePage" | findstr "OEMCP"

rem :: o comando retorna a saída assim :: OEMCP    REG_SZ    850

To change using the command line you can use the command below, noting that needed to run as administered:

reg add "HKLM\SYSTEM\CurrentControlSet\Control\Nls\CodePage" /v OEMCP /t reg_sz /d 850 /f

I’ve had problems when I needed to display a character that figured in chcp 65001, after I changed the value in the key, returning to the standard chcp 850, my batchs stopped displaying that same message with these characters..

has post that helped me: that was 1 that was another

Browser other questions tagged

You are not signed in. Login or sign up in order to post.