Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: simple batch file error  (Read 2369 times)

0 Members and 1 Guest are viewing this topic.

adrian916

    Topic Starter


    Newbie

    simple batch file error
    « on: March 22, 2010, 10:52:05 AM »
    I have created a simple batch file to record user logons and output the results to a csv file.
    When I run the file, it gathers the information correctly and creates the csv file but the csv is empty.
    By putting a pause into the batch file I can see that it is trying to interpret the first part of the output as a command and failing, but I can't understand why it is doing it.

    The batch file is:
    echo
    %date%,%username%,%computername% >>C:\logons.csv
    pause

    On running the batch file, the output is:

    22/03/2010,user1,pc1
    '22' is not recognised as an internal or external command.

    As you can see, the output data/variables are as expected and the logons.csv file is created, but it can't write the data to the file as it seems to think that the '22' from the date is a command.

    Any ideas what is causing this?

    Thanks

    Sidewinder



      Guru

      Thanked: 139
    • Experience: Familiar
    • OS: Windows 10
    Re: simple batch file error
    « Reply #1 on: March 22, 2010, 11:12:48 AM »
    Code: [Select]
    echo %date%,%username%,%computername% >>C:\logons.csv
    pause

     8)
    The true sign of intelligence is not knowledge but imagination.

    -- Albert Einstein

    Salmon Trout

    • Guest
    Re: simple batch file error
    « Reply #2 on: March 22, 2010, 12:33:23 PM »

    Any ideas what is causing this?

    Thanks

    As Sidewinder implies in his post, the echo command, and its parameters (what it is supposed to echo), have to be all on the same line. This, as he politely does not point out, is an elementary error.

    adrian916

      Topic Starter


      Newbie

      Re: simple batch file error
      « Reply #3 on: March 22, 2010, 01:38:01 PM »
      Thanks guys - easy when you know how! :)
      I knew it had to be something simple, as a previous one had worked in testing.
      I even showed it to a couple of guys at work and they didn't pick up on the line break either!
      Live and learn.