通过脚本/批处理/ ANT / Java代码等输入命令提示符的值

我想自动化一个应用程序。 在调用这个应用程序(它从一个批处理文件开始)时,它会显示一个命令提示符窗口,在其中请求值。

我的意思是:

  • 首先,它会要求您按ENTER (可以自动进行ENTER?)
  • 然后它要求一个路径(当然是String)
  • 然后再次询问另一个路径(字符串,再次)
  • 如何使用任何脚本/批处理/工具/ Java程序将这些值传递给命令提示符?

    现在这些值必须手动输入,我想自动执行此过程。 所以,在这里我不想手动输入它们,我想要一个脚本来完成它。 可能吗? 如果是,如何?


    这是这篇文章解决方案的副本,但根据您的特定需求进行了调整。 首先,“application.bat”:

    @echo off
    
    set /P "=Hit ENTER to continue"
    set /P "aPath=Enter a path: "
    set /P "anotherPath=Enter another path: "
    echo/
    echo I read "%aPath%" and "%anotherPath%"
    

    那么,解决方案:

    @if (@CodeSection == @Batch) @then
    
    
    @echo off
    
    echo Start the Batch file
    
    rem Use %SendKeys% to send keys to the keyboard buffer
    set SendKeys=CScript //nologo //E:JScript "%~F0"
    
    rem Start the "application" in the same Window
    start "" /B cmd /C application.bat
    
    rem Wait and send the first ENTER
    ping -n 2 -w 1 localhost > NUL
    %SendKeys% "{ENTER}"
    
    rem Wait and send the first path
    ping -n 2 -w 1 localhost > NUL
    %SendKeys% "C:Thefirstpath{ENTER}"
    
    rem Wait and send the second path
    ping -n 2 -w 1 localhost > NUL
    %SendKeys% "D:ASecondPath{ENTER}"
    
    goto :EOF
    
    
    @end
    
    
    // JScript section
    
    WScript.CreateObject("WScript.Shell").SendKeys(WScript.Arguments(0));
    

    输出:

    Start the Batch file
    Hit ENTER to continue
    Enter a path: C:Thefirstpath
    Enter another path: D:ASecondPath
    
    I read "C:Thefirstpath" and "D:ASecondPath"
    
    链接地址: http://www.djcxy.com/p/25555.html

    上一篇: Entering values to command prompt through a script/batch/ANT/Java Code etc

    下一篇: how do i create a shell script with multiple choice menu variables?