首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Powershell等待和发布

Powershell等待和发布
EN

Stack Overflow用户
提问于 2014-05-19 17:05:41
回答 1查看 246关注 0票数 1

我的脚本有点完整,但是我想在其中添加一些对进程的处理:

代码语言:javascript
复制
#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

这是非常出色的工作,唯一的问题是这条线:

代码语言:javascript
复制
& "C:\Program Files (x86)\BlueZone FTP\6.1\Bzftpf.exe" /F"ccaihfs.zft"

它在调用FTP程序。问题是这个过程需要一段时间。结果会被脚本的其余部分所操纵。但是powershell是如此之快,以至于它只是在文件传输完成之前做它必须做的事情。

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

我知道PS能处理这种情况。只是不知道怎么做。

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-05-19 17:13:59

听起来EXE是一个GUI应用程序,对吗?如果是这样的话,尝试这样做,让PowerShell在GUI应用程序退出之前等待:

代码语言:javascript
复制
& "C:\Program Files (x86)\BlueZone FTP\6.1\Bzftpf.exe" /F"ccaihfs.zft" | Out-Null
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23743387

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档