关于windows批处理脚本可靠性的问题

发布于 2024-10-12 05:55:11 字数 279 浏览 5 评论 0原文

我有一个很长的 Windows 批处理脚本。中间有一个部分使用 appcmd 来检测 IIS 中站点的根路径。该部分在独立执行时运行良好。但是,当我执行整个批次时,此部分可能偶尔无法检测到站点路径。我对这个不可靠的问题感到完全困惑。以前有人遇到过这个吗?

谢谢

解决方案

变量声明和生效之间似乎存在一些延迟。我更改了批处理文件某些部分的顺序,到目前为止它运行良好。我必须说,这仍然很奇怪。

I got a quite long windows batch script. In the middle of it there's a section using appcmd to detect the root path of a site in my IIS. That section runs fine when executed standalone. But when I execute the whole batch, this section could fail to detect the site path once in a while. I am totally confused by this unreliability issue. Have anyone met this before?

Thanks

Solution

It seems that there's some delay between a variable declaration and its coming into effect. I changed the order of some part of the batch file and it runs fine so far. I must say, it's still weird.

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

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

发布评论

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

评论(1

凉世弥音 2024-10-19 05:55:11

由于我不知道您的未知代码中存在什么类型的问题,因此我只能在批处理文件中显示已知的不可预测或随机行为。

1- 行尾的多任务回显
有时但并非总是如此,换行符和回车符会打印为 ASCII 字符 10/13(一个圆圈和一个注释),而不是开始新行。

@echo off
if "%1"=="/second" (
  call :task %2
  goto :eof
)
(call "%~0" /second 1 >con ) | ( call "%~0" /second 2 )
echo END OF TASKS
goto :eof

:task
for /L %%n IN (1,1,10) DO (
    echo This is task%1, output no %%n
    ping -n 2 localhost > nul
)

goto :eof

2- 有时但并非总是 %~^LF 的扩展崩溃,然后命令窗口立即关闭。

@echo off
set critical_content=hello%%~^

echo No crash
for %%a in (1 ) do (
    for %%x in (4) do (
        rem #%critical_content%#
    )
) 

As I don't know what type of problem you have in your unknown code, I can only show the known unpredicable or random behaviour in batch-files.

1- multiple tasks echo of line ends
Sometimes but not always the linefeeds and carriage returns are print as the ASCII-Chars 10/13 (a circle and a note) instead of begin a new line.

@echo off
if "%1"=="/second" (
  call :task %2
  goto :eof
)
(call "%~0" /second 1 >con ) | ( call "%~0" /second 2 )
echo END OF TASKS
goto :eof

:task
for /L %%n IN (1,1,10) DO (
    echo This is task%1, output no %%n
    ping -n 2 localhost > nul
)

goto :eof

2- Sometimes but not always an expansion of %~^LF crashes, then the command window closes immediatly.

@echo off
set critical_content=hello%%~^

echo No crash
for %%a in (1 ) do (
    for %%x in (4) do (
        rem #%critical_content%#
    )
) 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文