Vb 脚本中的两个任务重叠?
我是 VB Script 的新手,但由于它很简单,所以我从网上获取了两个代码片段,并将它们组合成一个,以便完成我的任务。
基本上我想要的是运行一个名为“MapForce.exe”的应用程序并生成一个输出文件,然后创建一个新目录并将该文件也复制到这个新目录。
代码很简单:
'This is the line to call MapForce.exe and produce output file.
createObject("wscript.shell").exec "C:\Program Files\Altova\MapForce2011\MapForce.exe 834toASCII.mfd /BUILTIN /LOG ACS.log"
'These are the lines to copy that output file to the new folder:
sourceDir = "C:\Documents and Settings\Robert\test\result.txt"
destinationDir = "C:\Documents and Settings\Robert\test\"
const OverwriteExisting = True
strDirectory = destinationDir & replace(Month(date),"/","_") & " TOU"
Set fso = CreateObject("Scripting.FileSystemObject")
if not fso.FolderExists(strDirectory) then
Set objFolder = fso.CreateFolder(strDirectory)
end if
fso.CopyFile sourceDir & "*.*", strDirectory & "\", OverwriteExisting
现在它可以运行:Mapforce.exe 运行,生成输出,创建新文件夹并将文件复制到新文件夹。但问题是,由于 MapForce 将需要更长的时间来完成并生成最新的输出文件,因此第 1 行需要更长的时间才能完成,但是,执行复制任务的其余行不会等待它完成,所以复制到新文件夹中的文件始终是旧文件,而不是应用程序生成的最新文件。
换句话说,剩下的几行赶紧完成任务,而不关心第一行(运行 MapForce 应用程序)是否完成。
所以我想知道专家是否可以给我建议如何强制剩余的行等待第一行完成并生成最新的输出?
I am new to VB Script, but since it is straight forward, so I grabbed two fragments of code from the web and combine them into one in order to do my task.
Basically what I want is to run an application called "MapForce.exe" and produce an output file, then create a new directory and copy this file to this new directory too.
The code is straightforward:
'This is the line to call MapForce.exe and produce output file.
createObject("wscript.shell").exec "C:\Program Files\Altova\MapForce2011\MapForce.exe 834toASCII.mfd /BUILTIN /LOG ACS.log"
'These are the lines to copy that output file to the new folder:
sourceDir = "C:\Documents and Settings\Robert\test\result.txt"
destinationDir = "C:\Documents and Settings\Robert\test\"
const OverwriteExisting = True
strDirectory = destinationDir & replace(Month(date),"/","_") & " TOU"
Set fso = CreateObject("Scripting.FileSystemObject")
if not fso.FolderExists(strDirectory) then
Set objFolder = fso.CreateFolder(strDirectory)
end if
fso.CopyFile sourceDir & "*.*", strDirectory & "\", OverwriteExisting
Now it works: Mapforce.exe gets run, output generated, new folder created and a file copied to the new folder. But the question is, since the MapForce will take a longer time to finish and produce the newest output file, so line 1 takes longer time to finish, however, the remaining lines of doing copying task don't wait for it to finish, so the file gets copied in the new folder is always the old one, not the newest one generated by the application.
To put it in another way, the remaining lines hurry to finish the task without caring whether the first line (which runs the MapForce application) finishes or not.
So I wonder if experts could give me advice on how to force the remaining lines to wait for the first line gets finished and newest output gets generated?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 WshShell.Run 方法。
样本:
You could use the WshShell.Run method.
A sample: