How to get echo work from a "client" PowerShell script?
I'm running a PowerShell script, which, call another script b开发者_StackOverflow社区y itself. In the first script, when I put echo, everything is OK, but I can't get any echo in the second ("client") script to show anything.
How can I get echo work?
I'm using PowerShell 2.0 on Windows 7 Pro, with PowerGUI. (I also tried with ISE, but it does not help)
You should use Write-Host directly insted of echo (witch is alias for Write-Output).
A sample of your script would help in giving an accurate answer. That said, I tried Write-Output from nested scripts and everything seems to working for me.
#Script1.ps1
Write-Output "Script 1"
Write-Output "Calling Script 2"
./Script2.ps1
#Script2.ps1
Write-Output "Script 2"
Write-Output "Script 2 End"
And, the output:
PS> .\Script-one.ps1
Script 1
Calling Script 2
Script 2
Script 2 End
You can use Write-Host to write to the console ( host)
There seems to be some confusion on using Write-Output vs Write-Host (echo is alias for Write-Output - you can see it from Get-Alias ). Write-Output is not just writing to console. From the docs:
Sends the specified objects to the next command in the pipeline. If the command is the last command in the pipeline, the objects are displayed in the console.
 加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论