0

I want to append an extra bit of text behind an already executed echo command. For example "Done" or "Failed" based on if something went well or not.

I am trying to create a batch file that checks if a file exists, then proceeds to the next step. I admit I'm not as good with batch, My current solution is, using goto statements, printing a new line with either if it went well or not.

Current solution:

@echo off
cls
echo Checking if the file is present...

if exist "file" goto :Next
color 4
echo File not found!
pause
exit

:Next
color a
echo Done.
:: Rest of the script continues here.

What I'm trying to do:

@echo off
cls
echo Checking if the file is present...

if exist "file" goto :Next
:: Here it should append "File not found!" at the end of the previous echo
pause
exit

:Next
:: Here it should append "Done." at the end of the previous echo

:: Rest of the script continues here.

The expected result would in simple terms allow something at the end of an a line I previously output via echo, to be appended at the end, preferably with the colors (here I used red for failed, and green for success). Is this possible at all? If so, how would I go about doing it?

Please note, there is probably better ways to lay out my script, as mentioned I'm not good with batch.

Any help would be appreciated!

  • You don't appear to have attempted to perform the task you have explained is required. If we don't see your code, we cannot help you to fix it. This is not a free code writing service, please take the [tour] and read [ask] before [editing your question](https://stackoverflow.com/posts/56797851/edit) to bring it on topic for StackOverflow. – Compo Jun 27 '19 at 20:12

2 Answers2

3

(ab)use set /p to write without a linefeed:

@echo off
<nul set /p "=working...  "
timeout 3 >nul
echo done.
Stephan
  • 50,835
  • 10
  • 55
  • 88
-1

You can use -n for first command. It will not add newline for after echo.

echo -n "Checking if the file is present..."

Avi
  • 11
  • 3