Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
thomson1308
- Posts: 3
- Joined: 12 May 2016 08:00
#1
Post
by thomson1308 » 12 May 2016 09:52
Hi,
want to have such an result:
IF6040-PeripheralsServer-02
I have a variable:
and another String
Code: Select all
SET SERVICENAME=IF6040-PeripheralsServer-%ID%
echo %SERVICENAME%
My result is:
IF6040-PeripheralsServer-
What did i wrong?
Thanks
-
Squashman
- Expert
- Posts: 4486
- Joined: 23 Dec 2011 13:59
#2
Post
by Squashman » 12 May 2016 10:06
You have an extra space in your SET statement.
-
Squashman
- Expert
- Posts: 4486
- Joined: 23 Dec 2011 13:59
#4
Post
by Squashman » 12 May 2016 10:16
thomson1308 wrote:i did it....
thats the soluition:
Code: Select all
SET SERVICENAME="PeripheralsServer-%ID%"
I am not understanding how changing this SET statement fixed your problem?
The problem was you were referencing your variable incorrectly because the space is part of the variable name. You can test this at the cmd prompt.
Code: Select all
H:\>set /p ID =ID eingeben:
ID eingeben:02
H:\>set /p ID=ID eingeben:
ID eingeben:02
H:\>set ID
ID=02
ID =02
H:\>echo %ID% %ID %
02 02
-
thomson1308
- Posts: 3
- Joined: 12 May 2016 08:00
#5
Post
by thomson1308 » 12 May 2016 23:36
Okay, thanks again.
Thats it...i deleted the Space and it works.
Now i have another question:
I need a "do-while" for this:
Code: Select all
REM ID des PeripherieServers eingeben
set /p ID=ID eingeben:
echo %ID%
REM Beschreibung eingeben
set /p Description=Beschreibung eingeben:
echo %Description%
REM Dienstnamen ab V6.4 zusammensetzen
SET SERVICENAME="IF6040-PeripheralsServer-%ID%"
echo %SERVICENAME%
REM Dienstnamen < V6.4 zusammensetzen
SET SERVICENAME2="IF6040PS%ID%"
echo %SERVICENAME2%
REM Beschreibung ändern
sc description %SERVICENAME% "%Description%"
sc description %SERVICENAME2% "%Description%"
Pause
The do while only ends when i type EXIT...
-
Squashman
- Expert
- Posts: 4486
- Joined: 23 Dec 2011 13:59
#6
Post
by Squashman » 13 May 2016 07:49
There is no native do while commands in batch. Nor do I see any type of looping or branching in your batch file so I have no idea what you are trying to accomplish.
-
pieh-ejdsch
- Posts: 240
- Joined: 04 Mar 2014 11:14
- Location: germany
#7
Post
by pieh-ejdsch » 14 May 2016 06:05
you mean this
Code: Select all
setlocal
rem %0 liest aus einer Eingabe am prompt
rem Anwendung liest auch aus einer Pipe
:: (echo 03& echo testname) | Anwendung
rem Anwendung liest auch aus einer Datei
:: Anwendung <filename
:DoWhile
set "EL="
(call;)& :: Errorlevel=0
REM ID des PeripherieServers eingeben
call :readin ID "ID eingeben: "
if errorlevel 2 goto :endwhile
echo %ID%
REM Beschreibung eingeben
call :readin Description "Beschreibung eingeben: "
if errorlevel 2 goto :endwhile
echo %Description%
goto :DoNext
:readIn Var "message"
if errorlevel 1 set /a EL +=%errorlevel% &echo(
set "IDMessage=%~2"
if ^%EL% equ 2 exit /b 2
set /p %1=%idmessage%||goto :readIn
call set "exit=%%%1%%"
if "%exit%" == "exit" exit /b 2
exit /b 0
:DoNext
REM Dienstnamen ab V6.4 zusammensetzen
SET SERVICENAME="IF6040-PeripheralsServer-%ID%"
echo %SERVICENAME%
REM Dienstnamen < V6.4 zusammensetzen
SET SERVICENAME2="IF6040PS%ID%"
echo %SERVICENAME2%
REM Beschreibung ändern
echo sc description %SERVICENAME% "%Description%"
echo sc description %SERVICENAME2% "%Description%"
goto :DoWhile
:endWhile
echo Aktion beendet
pipe into Batch or read from file
it Brakes when 2 empty lines or
pipe Ends
it also end this DoWhile with EXIT
Phil