Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在windows批处理中自动回答输入提示_Windows_Batch File - Fatal编程技术网

在windows批处理中自动回答输入提示

在windows批处理中自动回答输入提示,windows,batch-file,Windows,Batch File,在windows批处理中,我想启动一个程序,提示用户输入: >someProgram.exe > "Please enter "s" to start the program: > 如何将“y”输入自动传递到提示符,以便只需单击批处理即可启动程序 您想要这个: echo y | [Command] 例如:echo y | program.exe "echo <answer> | <batch command>" “echo对于多个输入,请执行以下

在windows批处理中,我想启动一个程序,提示用户输入:

>someProgram.exe
> "Please enter "s" to start the program:
> 
如何将“y”输入自动传递到提示符,以便只需单击批处理即可启动程序

您想要这个:

echo y | [Command]
例如:echo y | program.exe

"echo <answer> | <batch command>"

“echo

对于多个输入,请执行以下操作:


(echo input1和&echo input2)| program.exe

您可以使用VBScript自动执行用户输入提示,然后编写命令以在批处理脚本中运行VBScript

"echo <answer> | <batch command>"
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "command_that_asks_for prompt", 9 
WScript.Sleep 500 

'Msg is first prompt answer
Dim Msg: Msg = WshShell.ExpandEnvironmentStrings( "%DB_TYPE%" )

'send character by character using for loop for first input prompt
For i = 1 To Len(Msg)
WScript.Sleep 200
WshShell.SendKeys Mid(Msg, i, 1)
Next

WshShell.SendKeys "{ENTER}"

'Msg2 is second input prompt answer
Msg2 = WshShell.ExpandEnvironmentStrings( "%CONNECTION_TYPE%" )


' send character by character for second input prompt
For i = 1 To Len(Msg2)
   WScript.Sleep 200
   WshShell.SendKeys Mid(Msg2, i, 1)
Next

WshShell.SendKeys "{ENTER}"
上面的代码是为2个用户输入提示提供答案的示例。类似地,我们可以提供多个提示。这里我尝试提供环境变量作为输入提示的答案。 上述代码可以另存为filename.vbs,然后以批处理脚本的形式将命令写入VBScript

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "command_that_asks_for prompt", 9 
WScript.Sleep 500 

'Msg is first prompt answer
Dim Msg: Msg = WshShell.ExpandEnvironmentStrings( "%DB_TYPE%" )

'send character by character using for loop for first input prompt
For i = 1 To Len(Msg)
WScript.Sleep 200
WshShell.SendKeys Mid(Msg, i, 1)
Next

WshShell.SendKeys "{ENTER}"

'Msg2 is second input prompt answer
Msg2 = WshShell.ExpandEnvironmentStrings( "%CONNECTION_TYPE%" )


' send character by character for second input prompt
For i = 1 To Len(Msg2)
   WScript.Sleep 200
   WshShell.SendKeys Mid(Msg2, i, 1)
Next

WshShell.SendKeys "{ENTER}"
例如:

@echo off
'command to run VBScript
filename.vbs
pause

这可以用作批处理脚本来自动回答输入提示。

我可以确认它与“del”命令一起工作,但与我的特定exe文件不一起工作。诸如“del”之类的内置windows命令与任意.exe之间是否存在差异?非常感谢。为此,我一起搜索了数小时。