Simple batch script does not print variable as intended [closed] - batch-file

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
What is wrong with this code? it is supposed to print hello world
#echo off
set message = Hello World
echo %message%
I wrote it in notepad, and I saved it as first.bat, but when I run it in cmd.exe, it tells me echo is off

Do not add extra space before the equal sign in the set command.
#echo off
set message=Hello World
echo %message%

Related

Quotations mark syntax in Windows Batch files [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
When I try to run
netsh -c interface ipv4 add neighbors “Wi-Fi” “192.168.1.1” “00-24-36-A0-A0-61” store=persistent
in a bat file, it comes out as
netsh -c interface ipv4 add neighbors ΓÇ£Wi-FiΓÇ¥ ΓÇ£192.168.1.1ΓÇ¥ ΓÇ£00-24-36-A0-A0-61ΓÇ¥
store=persistent
in cmd. What can I do to fix this so they show up as regular quotation marks?
note: I am just learning bat so if there is something really easy to spot that I'm completely missing, that's why.
For me, it looks like, you are using "Unicode"-Quotations copied out from Microsoft Word.
Copy them into Notepad and replace them by real Quotations '"'.

Why is processing of my batch game always exited on an IF condition? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I try to make a map giving some values, but when I run the command the .bat processing is exited.
This is the snippet of my code:
choice /c k >nul
if %errorlevel%==1 goto mchk
:mchk
if %mn%=10 goto playerlevel
:playerlevel
cls
echo test
pause
Instead of going to playerlevel, the console window gets simply closed.
if %mn%=10 goto playerlevel
Should be
if %mn%==10 goto playerlevel
= is not a valid comparison operator, so your code generates a syntax error and aborts processing. When you use the point-click-and-giggle method of executing a batch, the batch window will often close if a syntax-error is found. You should instead open a 'command prompt' and run your batch from there so that the window remains open and any error message will be displayed.

rename DAT file using bat command [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I have a DAT file that I need to rename and make a txt file. It currently is named PRV4W.SW and I want it to be PRV4WSW.txt. I've tried below but it does not seem to work. Thanks.
ren "C:\PRV 4\20200731\PRV4W.SW" "C:\PRV 4\20200731\PRV4WSW.txt"
ren "C:\PRV 4\20200731\PRV4W.SW.dat" "C:\PRV 4\20200731\PRV4WSW.txt"
Please try
ren "C:\PRV 4\20200731\PRV4W.SW" PRV4WSW.txt
The above command works fine in Win7.
BTW, the new name should not contain [drive:][path]
Please type
help ren
for the usage of the ren command.

SET command with spaces causes "was unexpected at this time" eror [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
When I use SET with spaces in the text I receive an error message. Why? Note: this call is inside of another function, I am using setlocal enabledelayedexpansion set at beginning of file.
This works with no error (no spaces in SET text):
:: Is the host up?
CALL :TEST_HOST_UP %REMOTE_SYSTEM%
IF %ERRORLEVEL% NEQ 0 (
set "RETVAL=Error_Unable_To_Reach_Host"
GOTO :FINISHED
)
Causes an error "was unexpected at this time":
:: Is the host up?
CALL :TEST_HOST_UP %REMOTE_SYSTEM%
IF %ERRORLEVEL% NEQ 0 (
set "RETVAL=Error Unable To Reach Host"
GOTO :FINISHED
)
The error message "was unexepected at this time" was actually a problem in the IF statement somewhere else in the code:
if [%RETVAL%]==[No_Errors_Found] (
Which is a common concern in scripting languages such as batch or shell, where you must put quotes around your variables:
if "[%RETVAL%]"=="[No_Errors_Found]" (
Thanks to #dxiv's help, I was able to debug the problem immediately - mainly by adding 'echo on' command to the code to provide verbose output.
More information on debugging batch scripts can be found here:
How can I debug a .BAT script?

Input as defined variable shows as empty [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I've this code:
#echo off
set/p user = Enter your username:
echo Hello %user%
pause >nul
But when I enter any value and press enter, the cmd.exe output doesn't show me the value.
Any help?
You cannot have a space between your variable and the equal sign.
It must be:
set/p user= Enter your username:
Note that user= does not have a space.

Resources