Input as defined variable shows as empty [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
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.

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.

Simple batch script does not print variable as intended [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
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%

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.

How do I check if %Points% < %PCP1% in batch? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I have two numeral values, %Points%, and %PCP1%.
I wish to have something like:
IF (%Points% < %PCP1%) (
cls
echo Not enough money!
echo Hit enter to return home
pause
goto 2
)
ELSE (
echo Confirm Purchase? Your Points after this purchase will be (%Points% - %PCP1%)
pause
)
It doesn't work. Please help. Thanks!
The less than operator is LSS i.e.:
IF (%Points% LSS %PCP1%) (
Other Operators are:
EQU: equal to
NEQ: not equal to
LSS: less than
LEQ: less than or equal to
GTR: greater than
GEQ: greater than or equal to

Resources