在执行命令行时询问时,将Y作为答案传递的脚本

时间:2016-03-10 11:04:34

标签: vbscript

在执行命令行时,我们可以编写一个VBScript来传递Y作为答案。方案如下所示。

命令行的输出示例

C:\Users>ctrk -h datafile

 Do you want to copy the test generated files to inbox(y/n):y
Trying to generate beat file  ...

Checking file creation.....
Heart file    : C:\Program Files (x86)\FWI\data\beat.zip  created

Press 'ENTER' to exit.

我尝试了以下解决方案

Set WSHShell = CreateObject("WScript.Shell")
WSHShell.Run "%comspec% /c "& " echo y  | ctr -h datafile , 1, true" 

但它提出以下问题 - 命令行的输出示例


C:\Users\>echo y  | ctrk -h datafile

 Do you want to copy the test generated files to inbox(y/n):Trying to generate beat file  ...

Checking file creation....
Heart file    : C:\Program Files (x86)\FWI\data\beat.zip  created

Press 'ENTER' to exit.

Exception occurred. Refer to the error log for details.

任何帮助将不胜感激..

1 个答案:

答案 0 :(得分:0)

尝试以下

Set WSHShell = CreateObject("WScript.Shell")
WSHShell.Run "%comspec% /c "& "ctr -h datafile , 1, false"
wait(2)
WSHShell.Sendkeys "y"
wait(2)
WSHShell.SendKeys "{ENTER}"