Learn about Windows PowerShell
Hey, Scripting Guy! Is there an easy way to save my script output to a text file rather than displaying it on screen? -- KP, Ogden, UT
Hey, KP. If you always want your script to save data to a text file rather than display it on screen, then you’re probably better off using the FileSystemObject and its file-writing capabilities. However, it appears as though you sometimes want to save data to a text file and sometimes want to display that data in a command window. So can you create a multi-purpose script like that?
Well, you could, but an easier way is to use the command shell redirection characters when you start the script. For example, you might typically start your script like this:
cscript myscript.vbs
That runs the script, and causes any Wscript.Echo commands to display their output in the command window.
However, you could also start your script like this, using the > command shell redirection command:
cscript myscript.vbs > c:\scripts\log.txt
In that case, nothing will be echoed to the screen; instead, all your Wscript.Echo commands will be written to the text file C:\Scripts\Log.txt.
In the preceding example, should C:\Scripts\Log.txt already exist it will be overwritten with any new information generated by the script. If you’d prefer to have new information appended to C:\Scripts\Log.txt, then start the script using this command:
cscript myscript.vbs >> c:\scripts\log.txt
can v save the data on the o/p screen as it is? along with the data tht is present in our program?
in the sense: if im writing a prog to say
the current value is : ____ and the user enters the values there.. is it possible to save all of this as a text file?
Hi all.
This option doesn't work when used on scheluded task.
I need to put any command in the script to do this.
Tks.
Strange, I ran this in a .bat file with a script that I run to see if PCs are responding on the network.
When I run the script manually, all 3 PCs come back as responding to pings.
When I run the .bat file, the txt file indicates that the PCs are not responding.
Why would this command return the opposite result of what is expected?
How can I output only the failed pings to the log.txt file?
okay, how can I change the color of the failed pings on that outputted >>log.txt file?
txt files don't have color attributes, try RTF but I don't know if a batch file will do that (or even VBScript, maybe it will)
I did a similar ping -> log file thing but what I did was display the results in a auto refresh html file and color coded the DIV behind the text based on the ping, I did it in powershell but VBScript will definitely work