Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
Cornbeetle
- Posts: 31
- Joined: 23 Nov 2015 09:34
#1
Post
by Cornbeetle » 07 Oct 2016 15:43
This is a short script I made to output user input to a text file using the xcopy method shared on dostips. After the user is finished typing, what can be done to exit the loop and "goto" a "finished" section?
Code: Select all
:start
set "key="
for /f "delims=" %%G in ('xcopy /W "%~F0" "%~F0" 2^>NUL') do if not defined key set "key=%%G"
set test=%key:~-1%
if "%test%"==" " (
set /p x=,<nul >>output_keys.txt
goto:start
) else (
set /p =%key:~-1%<nul >>output_keys.txt
goto:start
)
:finished
-
aGerman
- Expert
- Posts: 4678
- Joined: 22 Jan 2010 18:01
- Location: Germany
#2
Post
by aGerman » 07 Oct 2016 16:12
Seems you try to reinvent the wheel
viewtopic.php?f=3&t=5519To answer your question ...
Code: Select all
set test=%key:~-1%
if not defined test goto finished
As soon as Enter was pressed the captured character is a "Carriage Return" that will be declined in the next place.
Steffen
-
Cornbeetle
- Posts: 31
- Joined: 23 Nov 2015 09:34
#3
Post
by Cornbeetle » 07 Oct 2016 17:40
aGerman wrote:Seems you try to reinvent the wheel
viewtopic.php?f=3&t=5519To answer your question ...
Code: Select all
set test=%key:~-1%
if not defined test goto finished
As soon as Enter was pressed the captured character is a "Carriage Return" that will be declined in the next place.
Steffen
I didn't think of the "carriage return" character, thanks! Works perfectly.