我的脚本有点完整,但是我想在其中添加一些对进程的处理:
#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时,完成脚本。
发布于 2014-05-19 17:13:59
听起来EXE是一个GUI应用程序,对吗?如果是这样的话,尝试这样做,让PowerShell在GUI应用程序退出之前等待:
& "C:\Program Files (x86)\BlueZone FTP\6.1\Bzftpf.exe" /F"ccaihfs.zft" | Out-Nullhttps://stackoverflow.com/questions/23743387
复制相似问题