Deltax76
Deltax76

Reputation: 14263

How to get echo work from a "client" PowerShell script?

I'm running a PowerShell script, which, call another script by 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)

Upvotes: 1

Views: 689

Answers (3)

manojlds
manojlds

Reputation: 301417

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.

Upvotes: 1

ravikanth
ravikanth

Reputation: 25810

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

Upvotes: 1

Artem Tikhomirov
Artem Tikhomirov

Reputation: 21726

You should use Write-Host directly insted of echo (witch is alias for Write-Output).

Upvotes: 2

Related Questions