我使用powershell来调用sql存储过程,现在我想将输出的完整集合重定向到.ps1文件中,因为输出行可在powershell中执行。将PowerShell输出重定向到.ps1
我试图使用> output.ps1,它的工作原理,但我检查输出文件,它包含很多'...'来替换实际输出。
如何导出完整的输出?还将标题关闭?
谢谢。
我使用powershell来调用sql存储过程,现在我想将输出的完整集合重定向到.ps1文件中,因为输出行可在powershell中执行。将PowerShell输出重定向到.ps1
我试图使用> output.ps1,它的工作原理,但我检查输出文件,它包含很多'...'来替换实际输出。
如何导出完整的输出?还将标题关闭?
谢谢。
这取决于你如何调用存储过程。如果你在PowerShell中调用它,你应该能够收集输出,所以我假设你将它作为一个单独的任务开始它自己的窗口。没有你的实际例子,这里有一个从tasklist.exe命令收集输出的方法。你可能会发现它适用。
cls
$exe = 'c:\Windows\System32\tasklist.exe'
$processArgs = '/NH'
try {
Write-Host ("Launching '$exe $processArgs'")
$info = New-Object System.Diagnostics.ProcessStartInfo
$info.UseShellExecute = $false
$info.RedirectStandardError = $true
$info.RedirectStandardOutput = $true
$info.RedirectStandardInput = $true
$info.WindowStyle = [System.Diagnostics.ProcessWindowStyle]::Hidden
$info.CreateNoWindow = $true
$info.ErrorDialog = $false
$info.WorkingDirectory = $workingDir
$info.Filename = $exe
$info.Arguments = $processArgs
$process = [System.Diagnostics.Process]::Start($info)
Write-Host ("Launched $($process.Id) at $(Get-Date)")
<#
$process.StandardOutput.ReadToEnd() is a synchronous read. You cannot sync read both output and error streams.
$process.BeginOutputReadLine() is an async read. You can do as many of these as you'd like.
Either way, you must finish reading before calling $process.WaitForExit()
http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.redirectstandardoutput.aspx
#>
$output = $process.StandardOutput.ReadToEnd()
$process.WaitForExit() | Out-Null
Write-Host ("Exited at $(Get-Date)`n$output")
} catch {
Write-Host ("Failed to launch '$exe $processArgs'")
Write-Host ("Failure due to $_")
}
$output
重定向输出和错误流的最安全方法是使用[如何在PowerShell中异步捕获进程输出?](http://stackoverflow.com/q/24370814) –
你能分享你的输出吗? – Arpit
这里只是我的输出的一个简短示例... $ application = New-Object -ComObject Visio.Application $ documents = $ application.Documents $ document = $ documents.Add(“AMSGantt.vst”) $ pages = $ application.ActiveDocument.Pages $ page = $ pages.Item(1) $ shape500 = $ page.DrawLine(2,7.9,11,7.9) $ shape500.TextStyle =“Title” $ shape500.LineStyle =“标题“ $ shape500.Text =”Assignation deBarrières - 2012年12月17日,星期一“ – Apriljuly
它实际上使用powershell打开visio并在预定义模板上开始绘制形状。所以我想要的是将这些输出存储到.ps1中,以便我可以从powershell调用ps1文件来执行这些输出。 – Apriljuly