我使用expdp命令进行备份,并将输出重定向到文本文件中。在此过程中,控制台为空白。我希望编写一个powershell脚本,在执行expdp命令之前,将状态消息显示为"In “。我尝试使用“开始作业”命令,但是它无法将输出重定向到文本文件,因为它是后台作业。这里的任何帮助都是非常感谢的。下面是用于开始作业的代码。
$job = Start-Job -ScriptBlock {expdp username/password@database schemas="" directory="" dumpfile="" logfile="" REUSE_DUMPFILES=yes filesize=32G *> PROJECT.txt} -Name ExpdpJob
while ((Get-Job -Name ExpdpJob).State -eq "Running")
{
Write-Output "Expdp command is running"
}发布于 2018-12-06 20:07:15
要捕获标准输出,您必须使用接收作业命令。我已经用PowerShell 5.1测试了下面的代码,它可以工作。由于信息流(#6) 不支持,它将无法在较低版本中工作。下面的代码片段假装expdp运行了10秒,并等待每5秒显示一次“运行”消息,直到完成,然后捕获输出到接收-作业文件并删除作业。
$job = Start-Job -ScriptBlock {Start-Sleep -Seconds 10; Write-Host "test";} -Name ExpdpJob
while ((Get-Job -Name ExpdpJob).State -eq "Running")
{
Write-Output "Expdp command is running"
Start-Sleep -Seconds 5
}
Write-Output "Expdp command completed"
((Receive-Job $job) 6>&1) >> C:\temp\test123.txt
Remove-Job $job
Get-Content C:\temp\test123.txthttps://stackoverflow.com/questions/48798474
复制相似问题