【问题标题】:Batch Script "Timeout" Error: Invalid Syntax. Default option is not allowed more than 1 time批处理脚本“超时”错误:语法无效。默认选项不允许超过 1 次
【发布时间】:2013-08-01 20:30:09
【问题描述】:

首先,我使用的是 64 位 Windows 7,如果它有所作为的话。我有一个批处理文件,其中我正在使用“超时”功能,如下所示:

*code does some things*
timeout /t 100 rem wait for 100 seconds for the above thing to finish

如果我在命令行中执行timeout /t 100,它会像我预期的那样等待 100 秒。但是,在脚本中它给了我错误:

ERROR: Invalid syntax. Default option is not allowed more than '1' time(s).
Type "TIMEOUT /?" for usage.

timeout 的说明是 /t 等待秒数,/nobreak 忽略按键,/? 显示帮助消息。我不确定我遇到了什么语法错误,或者什么“不允许默认选项”,特别是因为它似乎在批处理文件之外工作得很好。

【问题讨论】:

    标签: windows batch-file timeout


    【解决方案1】:
    rem wait for 100 seconds for the above thing to finish
    timeout /t 100
    

    你不能在命令的同一行设置注释。

    【讨论】:

    • 哦,我的...我觉得很傻,不知道这一点。非常感谢您的快速回复!
    • 如何在 php 中使用 exec() 设置超时?
    【解决方案2】:

    注释是另一个命令。因此,如果您希望它在同一行上,则需要像这样使用 &。

    timeout /t 100 & rem wait for 100 seconds for the above thing to finish
    

    【讨论】:

      【解决方案3】:

      原来我是用 CR 而不是 LF 来结束我的台词。

      在 Notepad++ 中,我用 \n 替换了所有的 \r,它现在可以工作了。

      【讨论】:

        猜你喜欢
        • 2016-10-16
        • 2016-01-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-16
        • 1970-01-01
        • 2016-01-28
        相关资源
        最近更新 更多