2

I have a batch script test.bat and a text file log.txt which store errors of my test.bat.

I am using 2>> log.txt to store the errors at the end of my commands.

For example : mysql -u root -padmin -e "stop slave;" 2>> log.txt

And my log.txt display mysql is not recognized as an internal or external command so it's works fine.

I just want to know if it is possible to add the time before the error message in the log.txt like 20:51:23 mysql is not recognized as an internal or external command

I tried things like

%time%2>> log.txt

or

set time=%time%
time2>> log.txt

But it doesn't work. Any ideas ? Thanks in advance.

2 Answers 2

1

The echo set option echo's time without newline. so it will echo time and then the message right next to it.

echo|set /p= %time% >> log.txt
mysql -u root -padmin -e "stop slave;" 2>> log.txt
Sign up to request clarification or add additional context in comments.

1 Comment

pleasure, glad I could help
0

just try echo %TIME% >> log.txt

2 Comments

yes, but that will just echo the time including new line with the error below it
You're right. The requirement for the same line somehow eluded me maybe because of the line break. +1 for your answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.