Results 1 to 12 of 12

Thread: Can a DOS batch file write a text file?

  1. #1

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Can a DOS batch file write a text file?

    anyone have any documentation on how if possible to write out a text file using a dos batch file?

    for example in the dos batch file i want it to create a text file (doesn't matter where on the drive) that says HELLO

  2. #2
    Member
    Join Date
    Nov 2002
    Location
    Michigan
    Posts
    54

    Batch file

    Place the line below in the batch file and it will write the word hello in a text file.

    echo hello >Hello.txt

  3. #3
    PowerPoster jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    2,526
    Try the following (in a batch file):

    ECHO HELLO > TESTTEXT.TXT

  4. #4

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    what about error messages... can i write them out?

    lets say i have a line

    erase myfile.dll

    but the dll is in use so it can't be deleted and DOS tells me so.. can I output the error message from DOS into the text file?

  5. #5
    Frenzied Member
    Join Date
    Jul 2002
    Posts
    1,370
    Code:
    erase myifle.dll > mylog.log

  6. #6
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    BTW: ">" will create a new file (if it doesn't exist) or, will overwrite the file (if it does exist).

    ">>" Will append to an existing file.
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  7. #7

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    Originally posted by techgnome
    BTW: ">" will create a new file (if it doesn't exist) or, will overwrite the file (if it does exist).

    ">>" Will append to an existing file.
    nice.. thanks for the tips guys..

    i am having trouble registering components via a batch file when my app is launched.. but it is only sometimes.. so i want to track down the exact error..

  8. #8

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    Originally posted by jim mcnamara
    Code:
    erase myifle.dll > mylog.log
    if it creates the text file.. but it is empty.. does that mean no error occured erasing the file?

  9. #9

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    Originally posted by jim mcnamara
    Code:
    erase myifle.dll > mylog.log
    this doesn't output the error message.. it just outputs "c:\dir\myfile.dll" to the text file

  10. #10
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Newbury, UK
    Posts
    1,878
    Try this. I believe its right, but I have never actually used it :

    Redirection using only the > or >> symbols does not output error messages to the text file. To get error messages also, use 2> or 2>>.

    Examples:
    net use X: \\servername\share$ >>out.txt 2>>out-err.txt
    net stop servicename >>out.txt 2>>out-err.txt

  11. #11

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    Originally posted by JordanChris
    Try this. I believe its right, but I have never actually used it :

    Redirection using only the > or >> symbols does not output error messages to the text file. To get error messages also, use 2> or 2>>.

    Examples:
    net use X: \\servername\share$ >>out.txt 2>>out-err.txt
    net stop servicename >>out.txt 2>>out-err.txt
    this does not work

  12. #12
    Member
    Join Date
    Nov 2002
    Location
    Michigan
    Posts
    54

    Worked

    This process worked for me maybe i'm doing it differnetly then you are for trapping the error message. attached is my batch file and below are the steps that I used to validate this

    1) I went into VB and created blank project with just a form and called it the default name of Project1.exe, then I ran this project on the c drive of my machine
    2) I ran this batch file which tries to delete the project1.exe while it is running

    errorlog.txt is the file it created and test.bat is the file that I ran.
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width