Computer Hope

Microsoft => Microsoft DOS => Topic started by: adrian916 on March 22, 2010, 10:52:05 AM

Title: simple batch file error
Post by: adrian916 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
Title: Re: simple batch file error
Post by: Sidewinder on March 22, 2010, 11:12:48 AM
Code: [Select]
echo %date%,%username%,%computername% >>C:\logons.csv
pause

 8)
Title: Re: simple batch file error
Post by: Salmon Trout 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.
Title: Re: simple batch file error
Post by: adrian916 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.