String to a batch command problem

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Terraformer
Posts: 1
Joined: 29 Mar 2010 18:32

String to a batch command problem

#1 Post by Terraformer » 29 Mar 2010 18:36

Code: Select all

@echo off
break off
title Ultra's CMD
set /a i=0
cls

echo LOADING...
IPCONFIG |FIND "IP" > %temp%\TEMPIP.txt
FOR /F "tokens=2 delims=:" %%a in (%temp%\TEMPIP.txt) do set IP=%%a
del %temp%\TEMPIP.txt
set IP=%IP:~1%
echo %IP% >%temp%\ip.txt

cls
echo ____________________________WELCOME TO ULTRA'S CMD______________________________
echo ---------------------------------Information------------------------------------
echo COMPUTER NAME  : %computername%
echo COMPUTER IP    : %IP%
echo ________________________________________________________________________________
goto setcommand

:setcommand
set /a i=i+1
if %i% == 6 goto clear
echo.
set /p command=:

if %command%.==. goto setcommand
%command%
if %command% == cls goto clear
goto setcommand

:clear
cls
set /a i=0
echo ____________________________WELCOME TO ULTRA'S CMD______________________________
echo ---------------------------------Information------------------------------------
echo COMPUTER NAME  : %computername%
echo COMPUTER IP    : %IP%
echo ________________________________________________________________________________
goto setcommand


Whenever I include a space in my string, the command does not work and batch crashes. I'm trying to call on the command indirectly using the user's string input. The problem occurs after :setcommand. For example:
When I input and set the %command% variable to "start" everything works fine.
When I input and set the %command% variable to "start /max" my batch window just closes.
Any idea how to get rid of this problem?

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: String to a batch command problem

#2 Post by aGerman » 30 Mar 2010 10:51

Try to use quotes

Code: Select all

set /p "command=:"

if "%command%"=="" goto setcommand
%command%
if "%command%"=="cls" goto clear


Regards
aGerman

---saster---
Posts: 5
Joined: 07 Apr 2010 06:49

Re: String to a batch command problem

#3 Post by ---saster--- » 07 Apr 2010 07:54

or maybe

["%command%"]==[""] goto setcommand

Post Reply