Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoiding newline in write-output

Tags:

powershell

I want to collect all output from my script in a log file and must use write-output instaed of write-host.

Write-Output "Server:" $a looks like

Server:
foo
.

Do I really have to write to write
write-output $("sfdghk:" + $a) to get Server:Foo

Thanks -jt

like image 261
ithyme Avatar asked May 27 '11 09:05

ithyme


People also ask

What is NoNewLine PowerShell?

In the case of the NoNewLine parameter, it is listed in the What's new in Windows PowerShell 5.0 article, and so that makes it easy to find. At other times, it means paying attention or actually searching by comparing commands from previous versions with commands from the latest version.

What is the difference between write-host and write output in PowerShell?

In a nutshell, Write-Host writes to the console itself. Think of it as a MsgBox in VBScript. Write-Output , on the other hand, writes to the pipeline, so the next command can accept it as its input. You are not required to use Write-Output in order to write objects, as Write-Output is implicitly called for you.


1 Answers

Found somewhere on the Internet:

Write-Output "Server: $($a)"

Works great in my code.

like image 122
Piotr S. Avatar answered Oct 21 '22 20:10

Piotr S.