1. #1
    jcgriff2's Avatar
    Join Date
    Feb 2012
    Location
    New Jersey Shore
    Posts
    16,166
    • specs System Specs
      • Manufacturer:
        HP
      • Model Number:
        HP ENVY TouchSmart 17-j130us Notebook - E8A04UA
      • Motherboard:
        HP Insyde 720265-501 6050A2549501-MB-A02
      • CPU:
        Intel Core i7-4700MQ Processor with Turbo Boost up to 3.4GHz.
      • Memory:
        12GB DDR3L SDRAM (2 DIMM)
      • Graphics:
        Intel HD graphics 4600 with up to 1792MB total graphics memory
      • Sound Card:
        Beats Audio quad speakers and two subwoofers
      • Hard Drives:
        1TB 5400RPM hard drive with HP ProtectSmart Hard Drive Protection
      • Disk Drives:
        Hitachi 500 GB SSD; 7 TB USB External
      • Power Supply:
        90w
      • Case:
        Laptop
      • Display:
        17.3-inch diagonal HD+ BrightView LED-backlit touchscreen display (1600 x 900)
      • Operating System:
        Windows 8.1

    Batch File Execution - Redirect Command (CMD) Screen Output to a File (All Windows)


    Batch File Execution
    Redirect Command (CMD) Screen Output (stderr) to a File


    I've always enjoyed using batch files for certain tasks as it saves me time and is relatively easy. Debugging batch scripts often involves reviewing the output generated on the CMD screen itself, which is not always easy -- especially if you have ECHO enabled (@echo on) and have long sub-directory names which results in the text wrapping, depending on your CMD "Property" settings.

    You can make debugging via CMD screen information easier by redirecting the CMD screen output (aka "stderr") to a file by executing your batch file via CMD line command using the following format:
    Code:
     batch file > CMD screen output file name 2>&1
    Code:
    YourBatchFile.bat > "%userprofile%\documents\CMDScreenOutput.txt" 2>&1
    As you know, the red and blue file names are variable; the 2>&1 is constant.

    So now instead of scrolling through and trying to discern the wrapped-line output of the command shell screen, you can do so in Notepad or your favorite text editor. :)

    Some of you may know the CMD screen output as stderr and the more commonly known and used redirection output (via > or >>) as stdout, which reminds me a little of my IBM mainframe JCL days (SYSABOUT, SYSPRINT, SYSOUT, SYSUDUMP, SYSDBOUT). :)




    Additional Information
    Ignoring the output of a command - Mark Yocom's Script Tips - Site Home - MSDN Blogs
    Hidden features of Windows batch files - Stack Overflow
    Command Redirection, Pipes | Windows CMD | SS64.com
    Batch files - Redirection (Rob van der Woude's Scripting Pages)
    Last edited by jcgriff2; 03-04-2015 at 10:15 PM.

    BSOD Posting Instructions - Windows 10, 8.1, 8, 7 & Vista ` ` `Carrona Driver Reference Table (DRT)
    https://www.sysnative.com/
    Sysnative Hex-Decimal-UNIX Date Conversion

    Has Sysnative Forums helped you?
    Please consider donating to help support the forum.
    Thank You!

    Microsoft MVP 2009-2015
    Windows Insider MVP 2018 - Present


    • Ad Bot

      advertising
      Beep.

        
       

Similar Threads

  1. [BATCH/VBS] List File Associations - ASSOC CMD
    By jcgriff2 in forum Windows Tips & Tricks
    Replies: 9
    Last Post: 10-10-2013, 12:41 AM
  2. (Remote) VBS/Batch Writing/Execution
    By AoN in forum Programming
    Replies: 69
    Last Post: 12-21-2012, 12:37 AM
  3. Sysinternals Updater - batch file
    By jcgriff2 in forum Windows Tips & Tricks
    Replies: 0
    Last Post: 11-04-2012, 05:27 PM
  4. WMI Battery Status - Batch file
    By jcgriff2 in forum Windows 8 | Windows RT Tutorials
    Replies: 0
    Last Post: 09-15-2012, 10:50 PM

Log in

Log in