[英]C# Piping commands into PowerShell
我需要一個接一個地運行兩個powershell命令,我應該創建兩次管道還是有更好的選擇? 謝謝
Runspace myRunSpace = RunspaceFactory.CreateRunspace(rc);
myRunSpace.Open();
Pipeline pipeLine = myRunSpace.CreatePipeline();
using (pipeLine)
{
Command myCommand = new Command("Get-Command...");
}
Pipeline pipeLine2 = myRunSpace.CreatePipeline();
using (pipeLine2)
{
Command myCommand = new Command("Get-Command...");
}
根據msdn,流水線就像“組裝線”一樣,因此,如果第一個命令的結果與第二個命令無關,則不需要流水線,可以改用ScriptBlock並使用一個RunspaceInvoke對象。
在這里查看示例。
如果您編寫了以下代碼,您會更滿意嗎?
using (Pipeline pipeLine = myRunSpace.CreatePipeline())
{
Command myCommand = new Command("Get-Command...");
}
?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.