calling saved data

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
batchcc
Posts: 139
Joined: 17 Aug 2015 06:05
Contact:

calling saved data

#1 Post by batchcc » 22 Sep 2015 13:31

sorry this question is so basic but using the following code

Code: Select all

@echo off
cls
Set /p name=
@echo @echo off > co.bat
@echo cls >> co.bat
@echo SET Name=%Name% >> co.bat
pause

SET /p Name= <co.bat
pause


how can i call the variable %name% and print it on the screen or use it in other places from a diffent file thanks.
Last edited by Squashman on 22 Sep 2015 13:43, edited 1 time in total.
Reason: MOD EDIT: Please use CODE TAGS.

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: calling saved data

#2 Post by Squashman » 22 Sep 2015 13:48

Not sure what you are trying to accomplish. Maybe you could give us some background on what you are trying to do.

Currently your %name% variable is equal to @echo off in your main batch file because you are redirecting the first line of your batch file into the name variable.

batchcc
Posts: 139
Joined: 17 Aug 2015 06:05
Contact:

Re: calling saved data

#3 Post by batchcc » 22 Sep 2015 15:17

So user enters his / her name which is stored in a batch or tmp file I can't figure out how to store it in a temp file so I used a batch file and then a second batch file a game will start by welcoming them for example hello user-name welcome.
Thanks

ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: calling saved data

#4 Post by ShadowThief » 23 Sep 2015 00:04

Code: Select all

set /p variable=<file.txt

sets %variable% to the first line of file.txt. In your example, all your would have to do to recall a value stored in a temp file is

Code: Select all

@echo off
cls
set /p "name=Name: " >file.txt
set /p name=<file.txt
pause

batchcc
Posts: 139
Joined: 17 Aug 2015 06:05
Contact:

Re: calling saved data

#5 Post by batchcc » 23 Sep 2015 08:45

sorry Shadowtheif I am having an issue calling the stored name

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: calling saved data

#6 Post by Squashman » 23 Sep 2015 09:06

Code: Select all

@echo off
cls
set /p "name=Name: "
echo %name%>name.txt
set /p name=<name.txt
echo %name%
pause

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: calling saved data

#7 Post by foxidrive » 23 Sep 2015 17:39

Is this your thread here too? OP: http://ss64.org/viewtopic.php?id=2044

TheHunterManX
Posts: 54
Joined: 14 Aug 2015 05:59

Re: calling saved data

#8 Post by TheHunterManX » 27 Sep 2015 06:21

I dont know if this helps but here:
@echo off
cls
REM if save exists echos name and exits
if exist co.bat goto Load
REM Type your name...
Set /p name=
REM Saves...
(
echo set name=%name%) > co.bat
REM Pauses without any pause text
pause >nul
REM calls saved data
call co.bat
REM shows saved data
echo %Name%
pause >nul
REM Relaunch to show saved data without having to retype it.
exit /b 0
:Load
call co.bat
echo %name%
pause >nul
exit /b 0

Post Reply