Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - how to get rid of line wrapping in powershell

Reply
 
Old 06-21-2007   #1 (permalink)
Harald Ums \(2179630\)


 
 

how to get rid of line wrapping in powershell

PS C:\Temp> '-' * 200 >a.txt
halfway correctly generates a line of 200 - and incorrectly adds an
additional newline
C:\Temp>powershell -command '-' * 200 >a.txt
wraps the line into two lines.

How can I get rid of these behaviors

Harald


My System SpecsSystem Spec
Old 06-21-2007   #2 (permalink)
dreeschkind


 
 

RE: how to get rid of line wrapping in powershell

You should probably check your results again. I can't reproduce this on my
machine.
I assume that your second command is actually:
PS> powershell -command "'-' * 200 >b.txt"

--
greetings
dreeschkind

"Harald Ums (2179630)" wrote:

> PS C:\Temp> '-' * 200 >a.txt
> halfway correctly generates a line of 200 - and incorrectly adds an
> additional newline
> C:\Temp>powershell -command '-' * 200 >a.txt
> wraps the line into two lines.
>
> How can I get rid of these behaviors
>
> Harald
>
>

My System SpecsSystem Spec
Old 06-21-2007   #3 (permalink)
dreeschkind


 
 

RE: how to get rid of line wrapping in powershell

You can use the .NET StreamWriter to avoid any additional newlines:

$streamWriter = new-object System.IO.StreamWriter('C:\Temp\a.txt')
$streamWriter.Write('-' * 200)
$streamWriter.Close()
$streamWriter.Dispose()

--
greetings
dreeschkind

"Harald Ums (2179630)" wrote:

> PS C:\Temp> '-' * 200 >a.txt
> halfway correctly generates a line of 200 - and incorrectly adds an
> additional newline
> C:\Temp>powershell -command '-' * 200 >a.txt
> wraps the line into two lines.
>
> How can I get rid of these behaviors
>
> Harald
>
>

My System SpecsSystem Spec
Old 06-21-2007   #4 (permalink)
Keith Hill [MVP]


 
 

Re: how to get rid of line wrapping in powershell

"Harald Ums (2179630)" <Harald_Ums@hotmail.com> wrote in message
news:ORP8qIDtHHA.2164@TK2MSFTNGP02.phx.gbl...
> PS C:\Temp> '-' * 200 >a.txt
> halfway correctly generates a line of 200 - and incorrectly adds an
> additional newline


It's a usability trade-off, right? If you had to manually provide a newline
for all output:

"Hi there`n"
"Here's another line`n"
"And here's another`n"

Then that would kind of suck. However I have been there, especially when
outputting to a file, when you really don't want that last newline. It
would be nice to have some control over that behavior. Perhaps something
like:

'-' * 200 | out-file -NoNewline a.txt

--
Keith

My System SpecsSystem Spec
Old 06-22-2007   #5 (permalink)
Harald Ums \(2179630\)


 
 

Re: how to get rid of line wrapping in powershell

actually the command is
c:\temp> powershell ./somescript >b.txt
I wasn't clear enough:
I ran powershell from a .cmd batch file (together with some other
non-powershell scripts)
As soon as the '>' is handled by cmd I get the wrapping
So in a way you solved my problem:
c:\temp> powershell "./somescript >b.txt"
does not do any wrapping

"dreeschkind" <dreeschkind@discussions.microsoft.com> wrote in message
news:5C4DD432-1EBB-43F2-A297-6D68505909A3@microsoft.com...
> You should probably check your results again. I can't reproduce this on my
> machine.
> I assume that your second command is actually:
> PS> powershell -command "'-' * 200 >b.txt"
>
> --
> greetings
> dreeschkind
>
> "Harald Ums (2179630)" wrote:
>
>> PS C:\Temp> '-' * 200 >a.txt
>> halfway correctly generates a line of 200 - and incorrectly adds an
>> additional newline
>> C:\Temp>powershell -command '-' * 200 >a.txt
>> wraps the line into two lines.
>>
>> How can I get rid of these behaviors
>>
>> Harald
>>
>>


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Printing Single Line From Powershell PowerShell
Text Line Wrapping Vista mail
Line not wrapping in sent email Vista mail
Wrapping PowerShell Scripts In A GUI Interface PowerShell
Powershell.exe command-line syntax PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46