My batch files (.cmd) sometimes run partial lines

I have a strange problem that I have never seen before for 30 years working with batch files. Given a dummy CMD file, for example:

@echo off
:somelabel
echo Testing something
dir /b
echo All is well.
:end

This basically works as expected, but sometimes I get output like 'ing something' is not recognized as an internal or external command, operable program or batch file.

This is clearly an event when he chopped off a little line and tried to execute the rest. When this happens, it is always the "random" part of the "random" line; it is not always an X string, or a loss of Y characters, or occurring where I have a particular combination of characters. It also does not affect only expressions echo; it can also try to execute abelor ir /b.

My system is a completely upgraded Win2008 R2, running on VirtualBox 5.0.2, running on a completely updated Linux Mint, running on Lenovo ThinkPad. Scripts are encoded by UTF-8.

... what's happening? How can i avoid this?

+4
source share
2 answers

Credit goes to @SomethingDark for comment:

The command line doesn't play nice with UTF-8. Use ANSI instead.

This seems to have solved the problem (as far as I can be sure of an intermittent problem).

+1
source

, , , . , , - Batch , cmd.exe " " Batch , . :

@echo off
:somelabel
(for /F "skip=1 delims=" %%a in (%~NX0) do echo %%a) > temp.tmp
del "%~NX0" & ren temp.tmp "%~NX0"
echo   Testing something
echo All is well.
:end

del ... & ren ... echo Testing something, ing something, @echo off . :

@echo offRL
echo   Testing something

RL CR + LF, "ing".

0

Source: https://habr.com/ru/post/1624795/


All Articles