批处理脚本不再起作用?

发布于 2024-11-05 16:10:24 字数 279 浏览 1 评论 0原文

我正在使用 Ant、Java 和 CVSNT 在控制台窗口中的命令行上工作。 (Unix 极客被迫生活在 Windows 世界

当我运行 cvsnt 命令时,批处理脚本不再起作用。这包括我使用的几个命令,包括 antvim

我可以打开一个新的控制台窗口,在该窗口中,一切都很好,所以它一定与该控制台窗口中的特定环境有关,每当我在 cvsnt 中执行某些操作时,就会发生这种情况。

有什么想法吗?有什么我应该寻找的吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

墨落成白 2024-11-12 16:10:24

我今天遇到了完全相同的问题。问题在于 cvs.exe 对代码页执行了某些操作。我无法解释清楚是什么,但如果您重置代码页,bat 文件将再次开始工作。

一个例子可能会让这一点更清楚(在英国,我的默认代码页是 850,但是当我将 Windows 默认代码页设置为 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

>

因此尽管代码页显然不受影响,但重置它会恢复 .bat 的功能文件。

为了解决这个问题,我使用了这样的脚本:

@echo off
(
chcp 850 > NUL
"C:\Program Files\CVSNT\cvs.exe" %*
chcp 850 > NUL
)

并通过它调用 cvs。如果有人可以评论为什么会发生这种代码页行为,我将最有兴趣知道。

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.

瑕疵 2024-11-12 16:10:24

CVSNT 2.5.05 将输出代码页设置为 65001 (UTF-8),并且不会将其设置回来。
不幸的是,Windows 对该代码页的处理被破坏,因此发生了糟糕的事情(包括无法运行批处理文件)。

一种解决方法是使用 CHCP 将代码页(输入和输出)重置为已知的工作代码页(437、850、1252 或其他),最好在同一行作为CVS命令。例如:

> cvs update & chcp 1252

或者,如果您觉得更奇特,您实际上可以保存当前代码页并恢复它。
例如,下面是我用来更新工作目录中所有模块的批处理文件:

@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

在同一行调用 CHCP 的重要性在于,如果代码页是 UTF,则不会处理批处理文件的下一行。

当然,修复bug将是更好的解决方案。

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.

╰沐子 2024-11-12 16:10:24

一些版本控制客户端(我正在与您交谈 ClearCase)启动一个子 shell,该子 shell 可能会也可能不会带来以前的环境。我们放弃了在 Unix 上编写 ClearCase 脚本的尝试,因为我们无法使用 CC 命令编写脚本,因为它们打开了一个子 shell,而父脚本将继续自行进入 la-la-land。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文