![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Files created by Powershell are over 2X bigger than files created bytext editor or cmd.exe. I'm trying to build telnet scripts using Powershell and run them with the Telnet Script Tool (TST) but files created by Powershell are not recognized as valid text/script files by TST. I discovered files generated by Powershell are more than twice the size of plain text files created outside of Powershell. Here is the test: [PowerShell] "test"> test.a [Cmd.exe] echo test> test.b A 'dir' of these files from a shell reveals: 05/16/2008 09:34 AM 14 test.a 05/16/2008 09:34 AM 6 test.b *Notice the size of the files. What's going on? The test.b file is appropriately 6 bytes: "test\r\n" = 6 chars. Where are the extra 8 chars coming from in the PS-created file? The files in any text editor appear identical and Textpad said they were identical as well. Then I opened a PS-created file in MS Word 2007 and saw non-printable chars before each char in the file. Please help. Thx. |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Files created by Powershell are over 2X bigger than files created by text editor or cmd.exe. Hello tom, It's not outputting in ASCII. (I beleive it's unicode) Do this: "test" |out-file -Encoding ascii test.c Karl Quote: > I'm trying to build telnet scripts using Powershell and run them with > the Telnet Script Tool (TST) but files created by Powershell are not > recognized as valid text/script files by TST. > > I discovered files generated by Powershell are more than twice the > size of plain text files created outside of Powershell. > > Here is the test: > [PowerShell] > "test"> test.a > [Cmd.exe] > echo test> test.b > A 'dir' of these files from a shell reveals: > 05/16/2008 09:34 AM 14 test.a > 05/16/2008 09:34 AM 6 test.b > *Notice the size of the files. > > What's going on? The test.b file is appropriately 6 bytes: "test\r\n" > = 6 chars. Where are the extra 8 chars coming from in the PS-created > file? > > The files in any text editor appear identical and Textpad said they > were identical as well. > > Then I opened a PS-created file in MS Word 2007 and saw non-printable > chars before each char in the file. > > Please help. Thx. > |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Files created by Powershell are over 2X bigger than files createdby text editor or cmd.exe. That did the trick! Thank you Karl. I was starting to go down that path (unicode vs. ascii), but hadn't nailed it yet. Can I make ASCII the default output encoding? Is this wise? Something that threw me off is $OutputEncoding. Why doesn't $OutputEncoding show Unicode? PS C:\> $OutputEncoding IsSingleByte : True BodyName : us-ascii EncodingName : US-ASCII HeaderName : us-ascii WebName : us-ascii WindowsCodePage : 1252 IsBrowserDisplay : False IsBrowserSave : False IsMailNewsDisplay : True IsMailNewsSave : True EncoderFallback : System.Text.EncoderReplacementFallback DecoderFallback : System.Text.DecoderReplacementFallback IsReadOnly : True CodePage : 20127 |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Files created by Powershell are over 2X bigger than files created by text editor or cmd.exe. Tom; I have no idea, and i have no idea ![]() Quote: > That did the trick! Thank you Karl. > > I was starting to go down that path (unicode vs. ascii), but hadn't > nailed it yet. > > Can I make ASCII the default output encoding? Is this wise? > > Something that threw me off is $OutputEncoding. Why doesn't > $OutputEncoding show Unicode? > > PS C:\> $OutputEncoding > IsSingleByte : True > BodyName : us-ascii > EncodingName : US-ASCII > HeaderName : us-ascii > WebName : us-ascii > WindowsCodePage : 1252 > IsBrowserDisplay : False > IsBrowserSave : False > IsMailNewsDisplay : True > IsMailNewsSave : True > EncoderFallback : System.Text.EncoderReplacementFallback > DecoderFallback : System.Text.DecoderReplacementFallback > IsReadOnly : True > CodePage : 20127 |
My System Specs![]() |
| | #5 (permalink) |
| | Re: Files created by Powershell are over 2X bigger than files createdby text editor or cmd.exe. On May 16, 6:36*pm, tom.lux...@xxxxxx wrote: Quote: > That did the trick! *Thank you Karl. > > I was starting to go down that path (unicode vs. ascii), but hadn't > nailed it yet. > > Can I make ASCII the default output encoding? *Is this wise? > > Something that threw me off is $OutputEncoding. *Why doesn't > $OutputEncoding show Unicode? > > PS C:\> $OutputEncoding > IsSingleByte * * *: True > BodyName * * * * *: us-ascii > EncodingName * * *: US-ASCII > HeaderName * * * *: us-ascii > WebName * * * * * : us-ascii > WindowsCodePage * : 1252 > IsBrowserDisplay *: False > IsBrowserSave * * : False > IsMailNewsDisplay : True > IsMailNewsSave * *: True > EncoderFallback * : System.Text.EncoderReplacementFallback > DecoderFallback * : System.Text.DecoderReplacementFallback > IsReadOnly * * * *: True > CodePage * * * * *: 20127 There are two major ways to write files in PowerShell — with the Out- File cmdlet and using the Set-Content cmdlet. Out-File will try to format the output and text files are written in Unicode by default. We can change that with -encoding parameter. Set-Content will simply write the output and use ASCII encoding. Also, when we pipe output data from PowerShell cmdlets into native applications, the output encoding from PowerShell cmdlets is controlled by the $OutputEncoding variable, which is by default set to ASCII. You could find more details here: http://blogs.msdn.com/powershell/arc...he-rescue.aspx -aleksandar http://powershellers.blogspot.com |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| zip files created within same month | PowerShell | |||
| Why are pgm created files, NOT shown in flder dir.? | Vista General | |||
| Reading the .dmp files created by BSODs | Vista performance & maintenance | |||
| Files created during upgrade from XP | Vista file management | |||
| Cannot access files created with XP | Vista account administration | |||