Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
Endoro
- Posts: 244
- Joined: 27 Mar 2013 01:29
- Location: Bozen
#1
Post
by Endoro » 14 Apr 2013 01:36
Hi, how can I put the current PROMPT in a variable?
Code: Select all
C:\TEST>prompt $g
>prompt $p$g
C:\TEST>
I tried somewhat like this:
Code: Select all
@echo off
for /f "delims=r" %%i in ('echo on^&for /f "delims=" %%a in ('echo') do rem') set "cPrompt=%%i"
echo(%cPrompt%
and much more, nothing worked.
-
abc0502
- Posts: 1007
- Joined: 26 Oct 2011 22:38
- Location: Egypt
#2
Post
by abc0502 » 14 Apr 2013 01:42
sorry, but what do you mean exactly ?
-
Endoro
- Posts: 244
- Joined: 27 Mar 2013 01:29
- Location: Bozen
#3
Post
by Endoro » 14 Apr 2013 02:20
Sorry, I'll explain better:
here I want
C:TEST> in a variable:
.. and here
14.04.2013>The current command prompt. Is there a way to put it in a variable?
-
foxidrive
- Expert
- Posts: 6031
- Joined: 10 Feb 2012 02:20
#4
Post
by foxidrive » 14 Apr 2013 02:33
Endoro wrote:The current command prompt. Is there a way to put it in a variable?
Why do you want to do that? We might think of something if we knew why...
-
jeb
- Expert
- Posts: 1062
- Joined: 30 Aug 2007 08:05
- Location: Germany, Bochum
#5
Post
by jeb » 14 Apr 2013 02:48
Yes, you can
Code: Select all
@echo off
setlocal
prompt $t
(
echo on
for %%a in (1) do (
rem
)
) > prompt.tmp
@echo off
< prompt.tmp (
set /p var=
set /p var=
)
set var
exit /b
This redirects the prompt to a file "prompt.tmp".
And then it can be read with FOR/F or set/p
jeb
-
Endoro
- Posts: 244
- Joined: 27 Mar 2013 01:29
- Location: Bozen
#6
Post
by Endoro » 14 Apr 2013 02:53
Thank you very much!
foxidrive wrote:Why do you want to do that?
I want to check an unknown "pushd" level with "prompt $+".
-
foxidrive
- Expert
- Posts: 6031
- Joined: 10 Feb 2012 02:20
#7
Post
by foxidrive » 14 Apr 2013 02:58
Endoro wrote:foxidrive wrote:Why do you want to do that?
I want to check an unknown "pushd" level with "prompt $+".
Why not compare with "%cd%"
Edit: I see what $+ does now.