{"id":71633,"date":"2004-08-17T15:56:00","date_gmt":"2004-08-17T15:56:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2004\/08\/17\/how-can-i-save-output-to-a-text-file\/"},"modified":"2004-08-17T15:56:00","modified_gmt":"2004-08-17T15:56:00","slug":"how-can-i-save-output-to-a-text-file","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-save-output-to-a-text-file\/","title":{"rendered":"How Can I Save Output to a Text File?"},"content":{"rendered":"<p><img decoding=\"async\" class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" height=\"34\" alt=\"Hey, Scripting Guy! Question\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" align=\"left\" border=\"0\"><\/p>\n<p>Hey, Scripting Guy! Is there an easy way to save my script output to a text file rather than displaying it on screen? <\/p>\n<p>&#8212; KP, Ogden, UT<\/p>\n<p><img decoding=\"async\" height=\"5\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" border=\"0\"><img decoding=\"async\" class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" height=\"34\" alt=\"Hey, Scripting Guy! Answer\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" align=\"left\" border=\"0\"><a href=\"http:\/\/go.microsoft.com\/fwlink\/?linkid=68779&amp;clcid=0x409\"><img decoding=\"async\" class=\"farGraphic\" title=\"Script Center\" height=\"288\" alt=\"Script Center\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/ad.jpg\" width=\"120\" align=\"right\" border=\"0\"><\/a><\/p>\n<p>Hey, KP. If you <i>always<\/i> want your script to save data to a text file rather than display it on screen, then you\u2019re probably better off using the FileSystemObject and its file-writing capabilities. However, it appears as though you <i>sometimes<\/i> 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?<\/p>\n<p>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:<\/p>\n<pre class=\"codeSample\">cscript myscript.vbs\n<\/pre>\n<p>That runs the script, and causes any Wscript.Echo commands to display their output in the command window.<\/p>\n<p>However, you could also start your script like this, using the &gt; command shell redirection command:<\/p>\n<pre class=\"codeSample\">cscript myscript.vbs &gt; c:\\scripts\\log.txt\n<\/pre>\n<p>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.<\/p>\n<p>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\u2019d prefer to have new information <i>appended<\/i> to C:\\Scripts\\Log.txt, then start the script using this command:<\/p>\n<pre class=\"codeSample\">cscript myscript.vbs &gt;&gt; c:\\scripts\\log.txt\n<\/pre>\n<p><br><\/p>\n<div>\n<table class=\"\" cellSpacing=\"0\" cellPadding=\"0\" width=\"100%\" border=\"0\">\n<tbody>\n<tr>\n<td class=\"\"><a href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/resources\/qanda\/aug04\/hey0817.mspx#top\"><img decoding=\"async\" height=\"9\" alt=\"Top of page\" src=\"http:\/\/www.microsoft.com\/technet\/mnplibrary\/templates\/MNP2.Common\/images\/arrow_px_up.gif\" width=\"7\" border=\"0\"><\/a><a class=\"topOfPage\" href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/resources\/qanda\/aug04\/hey0817.mspx#top\">Top of page<\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! Is there an easy way to save my script output to a text file rather than displaying it on screen? &#8212; 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\u2019re probably better off using the [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[3,4,14,5],"class_list":["post-71633","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-scripting-guy","tag-scripting-techniques","tag-text-files","tag-vbscript"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! Is there an easy way to save my script output to a text file rather than displaying it on screen? &#8212; 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\u2019re probably better off using the [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/71633","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=71633"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/71633\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=71633"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=71633"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=71633"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}