|
Answer» Hey guys.
I need some help with a batch file, i want to make a log file for "errors" with time, date AND comment.
so that when i open my batch file it ask me to write something and whatever i write it copys into my log file underneath my time and date. i tried this but it obviesly didnt work :/ help plz.
@ECHO OFF if exist error.txt ( set /p skriv= Error to repport?: @echo %time% %date% >> error.txt @echo %skriv% >> error.txt ) else ( set "." > error.txt ) @echo succes pause>nul Just a little TIDYING. If your error comment contains & < > | etc characters then use echo "%skriv%" with double quotes.
Code: [Select]@ECHO OFF set "skriv=" if NOT exist error.txt ( set /p "skriv=Error to report?: " >> error.txt echo %date% @ %time% >> error.txt echo %skriv% ) else ( echo success ) pause>nul
This will only run once, but you haven't really explained how you want it to function.It didnt work the text file only had time date and "echo off"
I want it to work like a log off errors, like i work maintainance on machines, when i´ve fixed a machine i want to be able to open the batch, write what error i had and when i press enter on the batch, it adds what i wrote into my log file together with time and date.
so that at any given time i can open my log.txt or (error.txt) and SEE all the errors and time + date of that error.
understand? If you want to append to a file then use this: The last version needed delayedexpansion to echo within the loop.
Code: [Select]@ECHO OFF set "skriv=" set /p "skriv=Error to report?: " >> error.txt echo %date% @ %time% >> error.txt echo "%skriv%" thank you so much, how come i have to set "skriv=" then set /p "skriv="?Quote from: Mekawy on April 17, 2013, 05:28:20 AM how come i have to set "skriv=" then set /p "skriv="?
It's error checking. %skriv% can be set in the same command session and WOULD then give an incorrect comment if enter alone was pressed without typing a comment.
This way it is initialised as an empty string and will only echo what is typed.
|