可以执行使用WshShell.Run
方法DOS命令:
var oShell = WScript.CreateObject("WScript.Shell");
oShell.Run("timeout /t 10", 1 /* SW_SHOWNORMAL */, true /* bWaitOnReturn */);
如果你特别需要,直到按下某个键或超时经过暂停脚本执行,你可以完成这使用WshShell.Popup
方法(带有超时选项的对话框):
var oShell = WScript.CreateObject("WScript.Shell");
oShell.Popup("Click OK to continue.", 10);
但是,此方法也会在cscript下运行时显示消息框。
本文描述了另一种可能的方法:How Can I Pause a Script and Then Resume It When a User Presses a Key on the Keyboard?简而言之,您可以使用WScript.StdIn
属性直接从输入流中读取,并以此方式等待输入。但是,从输入流读取不支持超时,并且仅在按下按键(而不是任何按键)时才返回。无论如何,这是一个例子,以防万一:
WScript.Echo("Press the ENTER key to continue...");
while (! WScript.StdIn.AtEndOfLine) {
WScript.StdIn.Read(1);
}
工作! thanx – detj 2009-09-18 07:10:11