Batch file: ECHO command. When a batch file is being executed, if echo is turned on, it would print the command currently it’s running on to the command prompt. By default echo is turned on for any batch file. We can turn off echo by including the following line in the beginning of the file. Windows Batch Scripting. From Wikibooks, open books for an open world. For /f 'tokens=*'%i in (list.txt) do @echo%i For each line in a file, echoes the line. Executing ECHO ON at the command prompt enables, and ECHO OFF disables echoing at the command prompt. ECHO defaults to OFF at the command line. The command-line ECHO is most useful when you are learning how to use advanced features. Similarly, executing ECHO ON in a batch file enables, and ECHO OFF disables echoing of batch file commands. ECHO defaults to ON in batch files. The current ECHO state is inherited by called batch files. I have a Windows.bat file which I would like to accept user input and then use the results of that input as part of the call to additional commands. For example, I'd. (Ab)using the PROMPT command As said before, the most commonly used prompt string is probably $P$G, which results in a prompt like this: C: > As you can see, this is one way of showing the '>' character on screen. If you would try to use ECHO to show the '>' character on screen, this would result in erroneous redirection of part of the echoed text to a file: ECHO C: > Fsx scenery downloads. DIR will result in a file named DIR which contains the text 'C: '. See More On Stackoverflow![]() ECHO C: >DIR *.BAT will result in an error message either stating that there are too many parameters (DOS), or that it cannot create a file with a wildcard in its long filename (the command would try to create a file named 'DIR *.BAT'). The ECHO command obviously isn't the right way to show characters on screen — at least not in a COMMAND.COM session; in NT's and OS/2's CMD.EXE these characters can be using carets ( ˆ ): ECHO C: ˆ>DIR *.BAT will display the text C: >DIR *.BAT on screen. In DOS (COMMAND.COM) we'll have to use the PROMPT command instead. Give More FeedbackAs we've seen before, $L shows a. So the following batch file would show some HTML tags on screen: @ECHO OFF REM Use temporary prompt to display greater than REM and less than characters on screen PROMPT $LHTML$G$_$LTITLE$G ECHO ON @ECHO OFF REM Restore default prompt PROMPT $P$G The empty line between the ECHO ON and the second @ECHO OFF line causes the prompt to be actually displayed: This trick may not work in OS/2 or NT, however. So instead of an empty line you could use%COMSPEC% /C without any further parameters, or%COMSPEC% /K EXIT to display the prompt. Using%COMSPEC% instead of CMD.EXE makes the batch file more versatile, since you leave it to the operating system to fill in the actual command processor. This way you can start the batch file in an NT or OS/2 command prompt as well as in a DOS emulation window. Combined with to temporary batch files this is an extremely powerful technique to perform complex and near-impossible tasks with 'plain simple DOS'. This combination of methods is the secret behind our example. A lot of trial and error led me this to this more or less operating system independent method to redirect 'unprintable' characters to files: PROMPT $_$LHTML$G$_$LHEAD$G$_$LTITLE$GMy Title$L/TITLE$G$_$L/HEAD$G$_$LBODY$G$_ ECHO EXIT XYZ|%COMSPEC% /K| FIND /V '| FIND /V 'EXIT XYZ' > TempFile.html This will create a file TempFile.html with the following content: My Title Instead of XYZ following EXIT, any 'unique' string can be used. Just make sure it is matched by the second FIND /V command (and, of course, that the first word is still EXIT). In the following example, where only one single line is redirected, the relevant line is filtered by searching for a 'unique' character or string within that line. PROMPT $_NewFiles$Q$Lnone$G$_ ECHO EXIT|%COMSPEC% /K| FIND '=' > MyIni.ini This will create a file 'MyIni.ini' with the following content: NewFiles= These last two examples will work in Windows 9x, NT 4 and 2000, and probably (!) in XP as well.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |