1.    10 May 2016 #1
    Join Date : Feb 2016
    Posts : 32
    Windows 10 Pro x64

    String with spaces in set /p (batch file)


    Hi! I would like to let a user type in things with spaces in set /p. This is the code I currently have that does not work:

    Code:
    :newdoc2
    cls
    echo What do you want to say?
    set saynew=%randomnum%
    set /p saynew=
    if %saynew% == %randomnum% goto newdoc2
    echo "%saynew%" >%namenew%
    goto start
    This works if saynew has no spaces, but not if it does. If I type, for example, "hello people", it will briefly say "hello was not expected at this time" and then crash. What did I do wrong? I tried putting "" around %saynew%:

    Code:
    echo "%saynew%" >%namenew%
    but it did not work. Any ideas?
      My ComputerSystem Spec
  2.    10 May 2016 #2
    Join Date : Feb 2016
    Posts : 32
    Windows 10 Pro x64
    Thread Starter

    If you need the whole thing, here it is:

    Code:
    @echo off
    title Text Reader
    color 17
    goto start
    set randomnum=%random%
    
    :start
    cls
    title Text Reader
    echo Type the location of the file and the filename. Type "end" to close, or type "new" to make a new document.
    set /p file=
    if %file% == new goto newdoc
    if %file% == end goto end
    if not exist %file% goto start
    goto main
    
    :main
    cls
    title %file%
    type %file%
    echo.
    echo (End of Document)
    echo Press any key to go back to start...
    pause >nul
    goto start
    
    :newdoc
    cls
    title New Document
    echo Type a name, and location if necessary.
    set namenew=0
    set /p namenew=
    if %namenew% == 0 goto newdoc
    :newdoc2
    cls
    echo What do you want to say?
    set saynew=%randomnum%
    set /p saynew=
    if %saynew% == %randomnum% goto newdoc2
    echo "%saynew%" >%namenew%
    goto start
    
    :end
    exit
      My ComputerSystem Spec

 


Similar Threads
Thread Forum
Solved Batch file: Who can solve this mystery?
I recenty migrated to Windows 10 from XP. Years ago, I made a batch file, ping.bat, to test my Internet connection and DNS server: ping 98.139.183.24 ping yahoo.com ping nytimes.com pause It works fine in XP, but when I run it in...
Software and Apps
Solved Start a program from a batch file
4 Apps of mine run a batch file that -tries- to call/start and EXE program. These Batch files need to work with OS XP thru Win 10. Win 10 has a pop-up window asking user if its okay to run/execute my EXE. No other Win version does this and thus I...
Software and Apps
Can't download batch file
Can't download batch file "10services_default.bat" to solve windows 10 start menu problem.
General Support
Solved Writhing Batch File
Here is my batch file but it will not delete the file? Must be missing something :( del "C:\Users\Larry\AppData\Local\TractorParts\tractor\ConfigSetting" Trying to delete the ConfigSetting File
General Support
Start a program from a batch file
I'm trying to create a batch file that should - call another batch file - start a program and then wait for the program to close - call another batch file My goal with this is to work around an issue in Windows 10 where the screensaver won't...
Software and Apps
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd
All times are GMT -5. The time now is 11:25.
Find Us
Twitter Facebook Google+ Ten Forums iOS App Ten Forums Android App



Windows 10 Forums