[英]PowerShell script doesn't get the text from the out file
The following code doesn't put text into the out file when I run it. 当我运行它时,以下代码不会将文本放入out文件中。 How do I correctly add the out file so that all the text from the shell gets copied to the out file?
如何正确添加out文件,以便将外壳程序中的所有文本复制到out文件中?
$connection = "localhost:19000"
$timeToRun = 60
$maxStabilizationTimeSecs = 180
$waitTimeBetweenFaultsSec = 10
$serviceName = "fabric:/OnServiceFabric.Policy.Deploy/PolicyService"
Connect-ServiceFabricCluster $connection
Invoke-ServiceFabricFailoverTestScenario -TimeToRunMinute $timeToRun -MaxServiceStabilizationTimeoutSec $maxStabilizationTimeSecs -WaitTimeBetweenFaultsSec $waitTimeBetweenFaultsSec -ServiceName $serviceName -PartitionKindSingleton
Pause | out-file c:\temp\results.txt
If you want the Output of Invoke-SeviceFabricFailoverTestScenario
in your results.txt
, you're breaking the Pipeline-Data by using pause
. 如果您要在
results.txt
输出Invoke-SeviceFabricFailoverTestScenario
的输出,则可以通过使用pause
中断管道数据。
If your really need pause
then try something like: 如果您确实需要
pause
尝试以下操作:
$connection = "localhost:19000"
$timeToRun = 60
$maxStabilizationTimeSecs = 180
$waitTimeBetweenFaultsSec = 10
$serviceName = "fabric:/OnServiceFabric.Policy.Deploy/PolicyService"
Connect-ServiceFabricCluster $connection
$data = Invoke-ServiceFabricFailoverTestScenario -TimeToRunMinute $timeToRun -MaxServiceStabilizationTimeoutSec $maxStabilizationTimeSecs -WaitTimeBetweenFaultsSec $waitTimeBetweenFaultsSec -ServiceName $serviceName -PartitionKindSingleton
Pause
$data | out-file c:\temp\results.txt
$connection = "localhost:19000"
$timeToRun = 60
$maxStabilizationTimeSecs = 180
$waitTimeBetweenFaultsSec = 10
$serviceName = "fabric:/OnServiceFabric.Policy.Deploy/PolicyService"
Connect-ServiceFabricCluster $connection
Invoke-ServiceFabricFailoverTestScenario -TimeToRunMinute $timeToRun `
-MaxServiceStabilizationTimeoutSec $maxStabilizationTimeSecs `
-WaitTimeBetweenFaultsSec $waitTimeBetweenFaultsSec `
-ServiceName $serviceName `
-PartitionKindSingleton | out-file c:\temp\results.txt
The pipeline needs to be on the same line as the command, otherwise it's interpreting it as a new command. 管道必须与命令在同一行,否则它将解释为新命令。
Additionally you can use backticks to tell the line to continue on the next line for neater code. 另外,您可以使用反引号来告诉该行继续进行下一行以获得更整洁的代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.