I am working on the command line in开发者_高级运维 the console window using Ant, Java, and CVSNT. (Unix geek forced to live in a Windows world)
When I run a cvsnt command, batch scripts no longer work. This includes several commands that I use including ant
and vim
.
I can open up a new console window, and in that window, everything is fine, so it must be something about that particular environment in that console window, and it happens whenever I do something in cvsnt.
Any ideas? Anything I should be looking for?
I had the exact same problem today. The problem is that cvs.exe does something with the code page. I cannot explain quite what but if you reset the code page, bat files start working again.
An example may make this clearer (being in the UK, my default code page is 850, but the same thing happens when I have my Windows default as 437)
>echo @echo .bat files are working > test.bat
>test.bat
.bat files are working
>chcp
Active code page: 850
>cvs update
? test.bat
cvs update: Updating .
>test.bat
>chcp
Active code page: 850
>test.bat
>chcp 850
Active code page: 850
>test.bat
.bat files are working
>
so although the code page is apparently unaffected, resetting it restores the functionality of .bat files.
To work around this problem, I am therefore using a script like this:
@echo off
(
chcp 850 > NUL
"C:\Program Files\CVSNT\cvs.exe" %*
chcp 850 > NUL
)
and invoking cvs through it. If anyone can comment on why this code-page behaviour is occurring I would be most interested to know.
CVSNT 2.5.05 sets the output code page to 65001 (UTF-8) and does not set it back.
Unfortunately, Windows' handling of that code page is broken so bad things happen (including the inability to run batch files).
One workaround is to reset the code page (both input and output) to a known working one (437, 850, 1252 or others) using CHCP
, preferably on the same line as the CVS
command. For example:
> cvs update & chcp 1252
Or, if you feel more fancy, you can actually save the current code page and restore it.
For example, here's a batch file that I use to update all the modules in my work directory:
@echo off
setlocal enableextensions
for /f "tokens=4" %%i in ('chcp') do set hack=chcp %%i
for /d %%i in (*) do (
if exist %%i\cvs (
echo.
echo *** updating %%i
pushd %%i
cvs -q update -A -P -d | find /V "?" & %hack% >NUL
popd
))
echo.
echo *** STATUS ***
cvs -q status -q | find /V "?" & %hack% >NUL
endlocal
pause
The importance of invoking CHCP on the same line is that the next line of the batch file will not be processed if the code page is UTF.
Of course, fixing the bug will be a better solution.
Some version control clients (I'm talking to you ClearCase) start a sub-shell which may or may not bring the previous environment over with it. We gave up trying to script ClearCase on Unix because we couldn't write scripts with the CC commands in them because they opened a subshell and parent scripts would continue by themselves into la-la-land.
精彩评论