在 HTML Javascript 中如何等待命令完成执行
我正在编写一个 HTML 菜单 (StartMenu.hta)。该菜单从 DVD 运行,但在运行之前需要将一些文件复制到用户的 TEMP 文件夹中。这些文件必须在菜单打开之前复制,因为这些文件是使用菜单所必需的。
为了复制这些文件,我使用以下 JavaScript 函数:
function launch(){
var shell = new ActiveXObject("WScript.Shell");
shell.run("xcopy \Data\\VLC\ \%TEMP%\\CSE\\VLC\ /d/e/i/y");
shell.run("xcopy \Data\\VIEWER\ \%TEMP%\\CSE\\VIEWER\ /d/e/i/y");
shell.run("StartMenuPC.hta");
}
我遇到的问题是复制和打开菜单同时开始,而不是最后一个命令等待前两个命令完成。 我曾考虑过使用批处理文件,但这可能会遇到与某些防火墙的冲突。
我还尝试过使用 while 循环,甚至检查文件是否存在于新位置,但因为我对 HTML 不太了解。我也不想使用超时,因为光盘只需要复制文件一次。
I am writing an HTML Menu (StartMenu.hta). This menu runs from a DVD, but before it can run it needs to copy a few files to the user's TEMP folder. These files have to be copied before the menu is opened, because these files are necessary for the use of the menu.
To copy these files, I use the following JavaScript function:
function launch(){
var shell = new ActiveXObject("WScript.Shell");
shell.run("xcopy \Data\\VLC\ \%TEMP%\\CSE\\VLC\ /d/e/i/y");
shell.run("xcopy \Data\\VIEWER\ \%TEMP%\\CSE\\VIEWER\ /d/e/i/y");
shell.run("StartMenuPC.hta");
}
The problem I have is that the copying and the opening of the menu start simultaneously, instead of the last command waiting for the previous two to finish.
I have considered using batch files instead, but that might encounter a conflict with some firewalls.
I have also tried using while loops and even checking to see if the files exist in their new location, but as I don't know a lot about HTML. I also don't want to use a timeout because the disc will only need to copy the files once.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
shell.run 采用第三个参数,该参数定义操作是否应该在继续之前完成。所以代码应该像
MSDN Windows Script Host Run方法 完整说明
shell.run
takes a third parameter which defines if the action should be completed before moving forward or not. So the code should be smth likeSee MSDN Windows Script Host Run Method for a complete explanation