2014-05-19 63 views
1

我的剧本是有点完整,但我想补充的过程中的一些处理它:PowerShell的等待和释放

#Call Bluezone to do file transfer 
& "C:\Program Files (x86)\BlueZone FTP\6.1\Bzftpf.exe" /F"ccaihfs.zft" 
#Variable Declarations 
$source = "\\fhnsrv01\home\aborgetti\Documentation\Stage\" 
$dest = "\\fhnsrv01\home\aborgetti\Documentation\Stage\orig" 
$archive = "\\fhnsrv01\home\aborgetti\Documentation\Stage\archive" 

#First copy the original file to the orig folder before any manipulation takes place 
Copy-item $source\*.EDIPROD $dest 
# Now we must rename the items that are in the folder 
Switch(GCI \\fhnsrv01\home\aborgetti\Documentation\Stage\*.EDIPROD){ 
    {(GC $_|Select -first 1).substring(176) -match "^834"}{$_ | ?{$_.Name -match "^.+?\.D(\d{6}).*"} | Rename-Item -NewName {"834Dailyin$($Matches[1]).txt"};Continue} 
    {(GC $_|Select -first 1).substring(176) -match "^820"}{$_ | ?{$_.Name -match "^.+?\.D(\d{6}).*"} | Rename-Item -NewName {"820Dailyin$($Matches[1]).txt"};Continue} 
    {(GC $_|Select -first 1) -match "NO INPUT"}{$_ | ?{$_.Name -match "^.+?\.D(\d{6}).*"} | Rename-Item -NewName {"NOINPUTin$($Matches[1]).txt"};Continue} 
    {(GC $_|Select -first 1) -match ""}{$_ | ?{$_.Name -match "^.+?\.D(\d{6}).*"} | Rename-Item -NewName Default {"Could not find 834 or 820 qualifier in file $_"};Continue} 
} 
#move files older than 1 month to archive 
$date = (get-date).AddDays(-31) 
GCI \\fhnsrv01\home\aborgetti\Documentation\Stage\*.txt| Where{$_.CreationTime -lt (get-date).adddays(-31)}| move-item -destination $archive 

此作品灿烂的是,唯一的问题是这一行:

& "C:\Program Files (x86)\BlueZone FTP\6.1\Bzftpf.exe" /F"ccaihfs.zft" 

这是调用一个FTP程序。问题是这个过程需要一段时间。结果与脚本的其余部分一起被处理。但是PowerShell的速度非常快,它只是在文件传输完成之前做它必须做的事情。

我在FTP程序中设置了一些自动配置选项,以便它在文件传输完成后自动关闭。这应该释放该程序的PID/mem。

我知道PS可以处理这种情况。只是不知道如何。

我想我想要做的就是把PS搁置,直到完成处理,然后当它释放PID时,完成脚本。

回答

1

听起来像EXE是一个GUI应用程序,对吧?如果是,请尝试使PowerShell等到GUI应用程序退出:

& "C:\Program Files (x86)\BlueZone FTP\6.1\Bzftpf.exe" /F"ccaihfs.zft" | Out-Null 
+0

正确。让我尝试! – Hituptony

+0

谢谢!像梦一样工作! – Hituptony