【问题标题】:What is making this program loop?是什么让这个程序循环?
【发布时间】:2015-10-05 20:31:51
【问题描述】:
:prompt
    set /p "asm_file_path=Enter full path name of asm file:"
pause

rem Validate the file path
:validate
    if not exist %asm_file_path% (
        echo Error! %asm_file_path% does not exist. Please enter valid file
        echo.
        goto prompt
    ) else (
        echo File found. Continuing...
        echo.
    )

我只是想获取用户输入并将其存储到 var asm_file_path 中。但是由于某种原因,程序进入了无限循环的错误!因为 var 等于 ""。我试过How to get two or more commands together into a batch fileHow to read input from console in a batch file? 甚至dos 指南,但我就是看不出这里有什么问题。

编辑 该程序不允许我输入任何内容。我使用的是 Windows 98。

【问题讨论】:

  • 问题是:在提示中输入什么,这个路径是否存在;我会写if not exist "%asm_file_path%" 以避免包含空格的路径出现问题(我还会在echo 中添加引号)...
  • 我在我的 Windows 10 机器上测试了你写的代码。也许你的文件不存在。或者可能没有输入路径。 (您是从某个地方重定向输入吗?)您必须提供更多信息。
  • 它没有给我机会输入任何东西。我使用的是 Windows 98。
  • Windows 98?当然? /P/A 开关已添加到 SET 命令 since Windows NT/2000
  • @JosefZ 是的,我刚刚找到一个告诉我的页面。您应该作为答案发布,以便我可以关闭此问题。

标签: windows batch-file input


【解决方案1】:

【讨论】:

  • 我将使用选择方法来读取输入。是的,Windows 98。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-03-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多