Vb 脚本中的两个任务重叠?

发布于 2024-11-09 01:25:54 字数 1192 浏览 0 评论 0原文

我是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

走走停停 2024-11-16 01:25:54

您可以使用 WshShell.Run 方法。

  1. 第一个参数(必需)是可执行文件(包括参数)。
  2. 第二个参数(可选)指定窗口样式。
  3. 第三个参数(可选)指定脚本是否等待命令完成后再继续。

样本:

Dim oShell
Set oShell = WScript.CreateObject("WScript.Shell")
returnCode = oShell.Run("Your.exe Param1 Param2", 1, True)

You could use the WshShell.Run method.

  1. The first parameter (REQUIRED) is the executable (including parameters).
  2. The second parameter (OPTIONAL) specifies the window style.
  3. The third parameter (OPTIONAL) specifies whether the scripts waits for the command to complete before continuing.

A sample:

Dim oShell
Set oShell = WScript.CreateObject("WScript.Shell")
returnCode = oShell.Run("Your.exe Param1 Param2", 1, True)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文