Batch scripts no longer work?
Asked Answered
H

3

2

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?

Haskins answered 6/5, 2011 at 15:5 Comment(9)
I type in the command "vim" and vim doesn't come up. It merely gives me a command line prompt. Same with "ant". Perl scripts do work though, and I have a whence.pl script that I can run which shows me which directory in the path a file is in. I can see that vim is C:\Windows\vim.BAT. For some reason, the command doesn't run and I just get a new prompt.Haskins
What does C:\Windows\vim.BAT contain? Does a simple test.bat file that contains only echo hello world also fail to do anything? Does it matter whether the test.bat file is in the current directory or that it's found by a search of the PATH?Aviation
Yup a simple test.bat also fails. This happens when I run cvs up or cvs commit.Haskins
What happens if you do C:\Windows\system32\cmd.exe /c test.bat?Aviation
Believe it or not, that fails. Just returns to the prompt. Very strange. It works on a clean client.Haskins
It's a bug in CVSNT. That may be unlikely but the next thing I'd start to consider is a virus/trojean/rootkit which is even more unlikely. It's times like these that bring Sherlock Holmes to mind, "... when you have eliminated the impossible, whatever remains, however improbable, must be the truth?"Schweinfurt
I know CVSNT is doing SOMETHING. I've checked for rootkits, and the only virus on my machine is all the "security" crap that corporate dumps on the box. The question is what. Next test, I'll open VI, shell out, then see if I get the same issue once I leave CVSNT.Haskins
Maybe if you run SETLOCAL before calling the CVS functions, then ENDLOCAL afterwards? This would protect the environment variables that the NT shell is using...Agentival
That's interesting advice. I'll have to give that a try.Haskins
N
6

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.

Nakano answered 6/6, 2011 at 21:18 Comment(2)
Thanks for the info! Doing the chcp 437 does fix it. I'll do the batch script like you said to fix this issue.Haskins
The guy next to me just ran into the same issue - he's wrapping it into a perl script, but this seems to work too.Dustcloth
P
3

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.

Paapanen answered 13/12, 2012 at 16:38 Comment(2)
Thanks for your explanation why CVSNT causes the problem. However, the question was asked and answered 2 1/2 years ago, so I can't give you credit for the answer. I'll +1 mod you though. In the end, I switched from CVSNT (which had myriad of other issues including being a piece of pesterware) to Subversion.Haskins
Some people still use CVSNT and search SO when getting these issues (I know I did) so I hoped it would help somebody. Cheers.Paapanen
S
0

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.

Schweinfurt answered 6/5, 2011 at 16:52 Comment(2)
'Tain't a sub-shell. If I type "exit", my console goes bye-bye. I also ran set and see all the environment variables as defined. As I said, all commands except for batch commands work fine. Unfortunately, ant and vim (the two I need the most) won't work.Haskins
Try capturing the return from the command that fails and then explicitly ECHOing it. Try defining an alias for said command that points to a batch file that just echos 'cmd executed' so you know that CVSNT is actually trying to execute the command.Schweinfurt

© 2022 - 2024 — McMap. All rights reserved.