Poon Lagoon
Poon Lagoon

Reputation: 35

Trying to Output Windows Environment Variables in a Simple CMD I'm Working on (Batch)

I am trying to output Windows Environment Variables in a simple CMD shell I'm currently working on. It's code is short and simple:

@echo off

cd %userprofile%

:begin

echo.

set cmd=
set /p cmd=%cd%^>

%cmd%

goto :begin

The purpose of this is to provide an "alternative" command prompt when the actual command prompt is disabled. All it does is takes the user's input as a command and outputs it. However, when attempting to output environment variables, it will output the raw variable name you put into it. Example, when I input "echo %time%" it will output "%time%" as opposed to something like "12:05:33.39". Is there any way I can implement some code that will allow for the output of environment variables? Thanks in advance.

Upvotes: 1

Views: 76

Answers (1)

SachaDee
SachaDee

Reputation: 9545

Try like this :

@echo off
cd %userprofile%
:begin
echo.
set cmd=
set /p cmd=%cd%^>^>
call %cmd%
goto :begin

You can take a look at the prompt command too prompt /?

example :

prompt $p-$t^>

Upvotes: 1

Related Questions