Solved

Batch file - echo a backspace

Posted on 2004-10-10
15
7,705 Views
Last Modified: 2013-11-18
I've love to know how to echo a backspace in a batch file.

For example:

echo Deleting file...
del file.txt
echo Done !

Will give a two line result not including any result from the delete command.  Can I echo a backspace to create a result that would show:

Deleteing file... Done !

WITHOUT a cls and re-echo ?


Simon
0
Comment
Question by:SimonUK
  • 3
  • 2
  • 2
  • +6
15 Comments
 
LVL 83

Expert Comment

by:oBdA
ID: 12272661
Not with the standard NT4/W2k/XP/W2k3 command shell, I'm afraid; the "echo" is always followed by a cr lf, and you can't (re)position the cursor. In Win9x/Me, you can load ansi.sys and use the escape command enabled there. But please don't try to use command.com in NT4 or later just for an optical gimmick; the NTVDM can be really ugly.
0
 
LVL 95

Expert Comment

by:Lee W, MVP
ID: 12272664
I don't think you can.  As I think about, it doesn't seem possible.  I'd like to see if someone else can say otherwise though.
0
 
LVL 27

Expert Comment

by:Asta Cu
ID: 12272913
Also don't think so; found this, though really unclear, did have echo backspace as an element in a search query ... looks like a research project.
This chapter defines routines to be used in other programs for
--  converting between internal and textual representations of data,
--  principally
http://web.comlab.ox.ac.uk/oucl/work/geraint.jones/publications/book/Pio2/code-formatted.txt

Have you checked MSDN?  
0
 
LVL 40

Expert Comment

by:Fatal_Exception
ID: 12273653
Yep..  as I mentioned in the other thread, I doubt it can be done either, at least not using a .bat file..

FE
0
 
LVL 17

Expert Comment

by:Jared Luker
ID: 12273947
AutoIT might have something for you (I'm not sure if it can be used in batch though.

http://www.hiddensoft.com/AutoIt/
0
 
LVL 1

Expert Comment

by:Niagol
ID: 12274717
Not sure if thats exactly what you are trying to do.  Without ANSI you cannot go up a line because your Echo ends and automatically drops down to the next line.  However if that is indeed what you are trying to do why not use "del file.txt /q" for quiet and then you will get no output at all which would result in

Deleting File...
Done !

Hope this helps.  
0
 
LVL 1

Author Comment

by:SimonUK
ID: 12274760
Thanks so far...

Yes the /q idea is great... but I'd really like to have:

Deleting file... Done !

Looks like it's not possible then... unless there's a batch extension program I could use but I'd rather the scripts worked on any machines with no mods.


Simon
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 1

Expert Comment

by:Niagol
ID: 12274885
You have an extremely bored person out here.  This requires something besides echo but not ANSI.  

Check out  http://www.chebucto.ns.ca/~af380/Tips.html#Tip011 for the EKKO command which would allow you to do what you want.
0
 
LVL 15

Expert Comment

by:Cyber-Dude
ID: 12275409
You will have to load the ANSI.SYS into memory shell while running the command prompt.
To do that, locate the config.nt file, located under <SystemRoot>\System32. Add the following line:
Device=ANSI.SYS

Save the file and start 'Command' (START => Run... => type 'command' and press 'Enter').

Start the editor by typing 'edit' and press 'Enter'.

See the following link to view all ANSI commands and how to use them. It will allow you to type Arrow Up/BackSpace and many other (including text color and symbols) forms to the batch file:
http://www.evergreen.edu/biophysics/technotes/program/ansi_esc.htm#notes

Good luck.

Cyber
0
 
LVL 2

Accepted Solution

by:
stokesj56 earned 300 total points
ID: 12280458
Try this:

@echo off
(Set /P MyVar=Deleting file...) < NUL
del file.txt
echo  Done !

The 2 square boxes are entered by holding the Alt key and entering 008 on the numeric key pad. Hitch here is you can't do this in Notepad or Wordpad. I use TextPad (http://www.textpad.com/) which allows the creation of this file.
0
 
LVL 95

Assisted Solution

by:Lee W, MVP
Lee W, MVP earned 200 total points
ID: 12280769
Stokesj56 - NICE!  However, it turns out, you don't need the backspace characters in there.  I'm not sure how this is working but the key seems to be using the "set /p myvar=what you want to say) < NUL"

I tested this by doing something I new would take a few seconds - here's my test script:
@echo off
(Set /P MyVar=Listing all files...) < NUL
dir /s c:\windows > .\windows.list
Echo Done!

This resulted in output of:
Listing all files...
(wait for the command to complete)
followed by the word Done! on the same line, effectively giving me:
Listing all files...Done!

Thus, notepad, "copy con filename.cmd", or virtually any other text editor can do this.
0
 
LVL 95

Expert Comment

by:Lee W, MVP
ID: 12280794
I will add, that if you want to erase characters on the MyVar line message, then you can use the embedding of ASCII codes (I wrote a VB app quickly that just "print"ed to a text file the text of the script, adding a couple of CHR(8)'s in there for the backspaces.

So if you wanted to do a:
Listing all files... and have the final line read
Listing all files - done

you would throw in 3 back spaces.

By the way, I realize this isn't my question, but can someone explain exactly how the redirection of input to NUL and setting that variable is making this work?
0
 
LVL 1

Author Comment

by:SimonUK
ID: 12284884
Someone once told me there is NOTHING you can't do in a batch file - they were RIGHT !

Thanks so much everyone.  Here's an example of usage.

@echo off
cls
echo.
(set /P MyVar=Checking internet connection... ) < NUL
ping www.yahoo.com | find "TTL" >NUL
if errorlevel 1 goto fail
echo OK!
echo.
(set /P MyVar=Checking local router... ) < NUL
ping 192.168.0.1 | find "TTL" >NUL
if errorlevel 1 goto fail
echo OK!
echo.
pause
exit

:fail
echo Failed!
echo.
pause
exit


Simon
0
 
LVL 40

Expert Comment

by:Fatal_Exception
ID: 12287139
Well, I certainly learned something new here..  thanks to everyone..

FE
0
 
LVL 2

Expert Comment

by:stokesj56
ID: 12293074
> By the way, I realize this isn't my question, but can someone explain exactly how
> the redirection of input to NUL and setting that variable is making this work?

From "help set":

  SET /P variable=[promptString]

This is a special form of the set command to prompt a user for input to be stored in a variable. Try this at a command (cmd) prompt:

C:\> set MyVar=
C:\> set
blah blah ... (Notice MyVar is not in this list)
C:\> set /P MyVar=Enter something:
Enter something: Something
C:\> set
blah blah ... (Notice MyVar is now set to the text you entered)
C:\> set MyVar=

Adding < NUL to this set line tells it to take input from the NUL device. Thus, it doesn't wait for user input. Because the prompt is presented with out a CR and the user doesn't enter one the cursor is left on the prompt line. Since we are setting the variable to nothing it does not actually get set in the environment (we don't need it).

Understand now? No real magic, just using a command in an unintended way to achieve a desired result.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Collapseable list of URLs. 10 100
I starting with php 12 94
use of cookies and regulations 1 53
SCCM And Branchcache Server 1 35
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now