Login | |
|
 |
RE: Why does Writeline leave a blank line at the end? - 12/12/2006 1:24:00 AM
|
|
 |
|
| |
ebgreen
Posts: 5246
Score: 31
Joined: 7/12/2005
Status: online
|
I actually get an error when I run that because I don't have a file C:\Temp\TestOut.txt. When I create an empty file, I only get two lines in it running the code.
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: Why does Writeline leave a blank line at the end? - 12/12/2006 1:30:30 AM
|
|
 |
|
| |
ginolard
Posts: 1082
Score: 21
Joined: 8/10/2005
Status: offline
|
It's bloody annoying. I want to read in a list of machines, scan them for something and then write out the offline machines to same file (so that the list of targets is gradually reduced as machines are scanned). However, that blank line thing is making my script bomb out. Grrr.
_____________________________
Author of ManagePC - http://managepc.net AD Query Template - http://www.visualbasicscript.com/m_40609/tm.htm Consolidated Scripting Framework - http://www.visualbasicscript.com/m_59109/tm.htm
|
|
| |
|
|
|
 |
RE: Why does Writeline leave a blank line at the end? - 12/12/2006 1:50:05 AM
|
|
 |
|
| |
ebgreen
Posts: 5246
Score: 31
Joined: 7/12/2005
Status: online
|
Well it is a hack, but you can trim the last line after you write the file: Set ObjFSO=CreateObject("Scripting.FileSystemObject") Set OutputFile=ObjFSO.CreateTextFile("C:\temp\testout.txt", True) OutputFile.Write "adsasdadadA" & VbCrLf OutputFile.Write "jhdfjhajdksfhjkadf" & VbCrLf OutputFile.Close strText = Left(objFSO.OPenTextFile("C:\temp\testout.txt").ReadAll(), Len(objFSO.OPenTextFile("C:\temp\testout.txt").ReadAll())-2) Set OutputFile=ObjFSO.CreateTextFile("C:\temp\testout.txt", True) OutputFile.Write strText OutputFile.Close() i = 0 For Each strLine In Split(objFSO.OPenTextFile("C:\temp\testout.txt").ReadAll(), vbLf) i = i + 1 WScript.Echo i & ")" & strLine Next
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: Why does Writeline leave a blank line at the end? - 12/12/2006 2:23:10 AM
|
|
 |
|
| |
ginolard
Posts: 1082
Score: 21
Joined: 8/10/2005
Status: offline
|
Payrise? What's a payrise? Yes, I know I can do all that. However, given that this is a one-off scan of all machines in the park I'm quite happy to leave it as a hack for now. That doesn't change the fact that I think WriteLine's behaviour is stupid ;) Of course, if I had any gumption at all today, I'd do it all in Powershell.
_____________________________
Author of ManagePC - http://managepc.net AD Query Template - http://www.visualbasicscript.com/m_40609/tm.htm Consolidated Scripting Framework - http://www.visualbasicscript.com/m_59109/tm.htm
|
|
| |
|
|
|
 |
RE: Why does Writeline leave a blank line at the end? - 12/12/2006 2:38:04 AM
|
|
 |
|
| |
TNO
Posts: 1399
Score: 16
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
|
I'm only half awake right now, but wouldn't it be easier to write all the results to a variable separated by vbnewline, then write() it all at once to the file?
_____________________________
To iterate is human, to recurse divine. -- L. Peter Deutsch
|
|
| |
|
|
|
 |
RE: Why does Writeline leave a blank line at the end? - 12/12/2006 2:39:33 AM
|
|
 |
|
| |
ebgreen
Posts: 5246
Score: 31
Joined: 7/12/2005
Status: online
|
I don't think WriteLine's behavior is stupid. It does exactly what it is supposed to do. It writes the string it is given and appends VbCrLf to it. How is it supposed to know that this is the last line that you intend to write to the file?
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: Why does Writeline leave a blank line at the end? - 12/12/2006 3:02:58 AM
|
|
 |
|
| |
TNO
Posts: 1399
Score: 16
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
|
You could always use JScript, that way you could use writeline, get pissed off that it does the same thing. Delete it, then prototype the exact same function into object so it works the way you want using 1,000 lines of extra code, then forget that you did that and wonder why nothing else is working right when you use that function later (I swear, this never happened to me......)
_____________________________
To iterate is human, to recurse divine. -- L. Peter Deutsch
|
|
| |
|
|
|
|
|