Reputation:
I made this batch file it works fine exceptfor submenu 4 where it redirects ping 192.168.1.1 -n 1 -w !thyme! to NUL instead of echo ping 192.168.1.1 -n 1 -w !thyme!>NUL to %dir101%
@echo off & SETLOCAL EnableDelayedExpansion
title TXTanimation
set dir101=C:\USers\%username%\Desktop\file.bat
goto label1
echo Lets make a text animation
pause
set /p dir101=where will the .bat be saved:
:label1
echo @ECHO OFF > %dir101%
echo: >> %dir101%
:menu
echo 0=Edit important information
echo 1=Display .txt
echo 2=Play sound
echo 3=Close sound player
echo 4=Add nessicary wait between .txt
echo 5=Label point
echo 6=Edit variable
echo 7=Goto point
echo 8=Create IF sentence
echo 9=End it
Set /p choose=which one:
If '%choose%'=='0' (
SEt /p title=What is the title
:LOL101
set /p color=what color do you want type test to experiment with the colors
If '!color!'=='test' goto tester
goto model
:tester
SEt /p test=Please give hexadecimal number type exit to leave:
if '!test!'=='exit' goto LOL101
color !test!
goto tester
:model
echo title %title% >> %dir101%
echo color %color% >> %dir101%
goto menu
)
If '%choose%'=='1' (
set /p dir=what is the dir of your .txt:
)
If '%choose%'=='1' (
echo cls >> %dir101%
echo type %dir% >> %dir101%
goto menu
)
If '%choose%'=='4' (
SEt /p thyme=How much milliseconds 250 is usual:
echo ping 192.168.1.1 -n 1 -w !thyme!>NUL >> %dir101%
goto menu
)
If '%choose%'=='9' (
echo Thanks for making
pause
exit /b
)
Yeh It's a big program but my error is real small. I could type the template and insert the variable maybe?
But echo ping 192.168.1.1 -n 1 -w !thyme!>NUL >> %dir101%
I need it to state the >NUL to be redirected
Upvotes: 0
Views: 865
Reputation: 130879
You simply need to escape the redirection symbol so that it gets echoed instead of being interpreted as redirection.
echo ping 192.168.1.1 -n 1 -w !thyme! ^>NUL >>%dir101%
Warning: your submenu 0 works as written, but you may be establishing a bad habit that will cause problems for you in the future. You generally should not put a label inside a parenthesized code block. Read (Windows batch) Goto within if block behaves very strangely for an example of how that can cause problems, and the selected answer explains why it can cause problems.
Upvotes: 1
Reputation: 706
You need to properly escape those commands when you are trying to echo them into another batch. Try this:
echo ping 192.168.1.1 -n 1 -w ^!thyme^!^>NUL >> %dir101%
which writes this into your %dir101%
batch:
ping 192.168.1.1 -n 1 -w *value_of_thyme_variable* > NUL
the ^
escapes most functions in batch.
FYI: this does not work on %
variable values. If you need to escape a %
variable value like %test%
you can do it like this: %%test%%
, but as you can see it does work for the !
variable value above.
Upvotes: 1