When I run following command on cmd it ask me to press enter to continue. when I press enter it show the next thing and so on.we do this when develop/create a new firefox addon using jpm tool.first it show default title if I hit enter it show default name and etc...
command jpm init
here is an snapshot
now I want to make a bat file for this. so it should go to next line like when I press enter .
I tried this. but it doesn't go to next line it show title..and wait..
create.bat
call jpm init
echo
echo
echo
echo
echo
echo
pause
How can I make a bat file for this?
Try this:
(
echo/
echo/
echo/
echo/
echo/
echo/
) | call jpm init
pause
another method, that may (or may not) work for you:
<nul call jpm init
Whenever an input is required, it is taken from the NUL device.
Pro: no need to know how many inputs are required
Con: every input request is answered with RETURN
Related
As a small training for my batch programming I originally followed the idea to make up a small slotmachine. You can give your coins, the numbers rush through and when you hit a button, the numbers should stop at their current value. If they are all the same, boom, you won the jackpot!
My problem right now is the keystroke capture during the loop. I already thought something like a choice command, but then the program would stop at each loop waiting for keyboard input, not making the game just quite annoying to wait all the time, but as well boring as you could check if you want to hit a specific button to stop.
Another thought was putting
set /p foobar=
and then simulate an Enter-Stroke with !SendKeys! (with everything neccessary in the code), forgetting that the enter yould have been sended after input...
Is there a way to accomplish that in ONE batch file? Or do I have to come up with another one to simulate the keystrokes or is there anything else I have missed?
EDIT: To clearify: Is there any command that changes something on keystroke, but runs through if nothing is touched?
Thanks for help in advance!
Greetings
geisterfurz007
#echo off
setlocal EnableDelayedExpansion
rem Create an empty file
cd . > key.txt
rem Start a parallel process that wait for Enter key
rem and add a line to the empty file
start "" /B cmd /C "set /P = & echo line >> key.txt"
set "key="
:wait
cls
set "number=%random:~-4%"
echo %number%
echo/
echo Press Enter key to stop the numbers...
set /P key=< key.txt
if not defined key goto wait
echo The last number is: %number%
I am trying to learn Batch.
I wrote a simple code with two labels.
This is the code:
#echo off
title intro
color 1f
::############################
::label
:one
cls
echo hello
echo. please enter your First name
echo.
:: fname is a variable (type p - string) that will content the user input. the input will be insert after <<
set /p fname= ">>"
echo.
echo. please enter your Last name
set /p lname=">>"
echo.
echo hello %fname% %lname%!
pause>nul
goto two
::############################
:two
cls
echo. welcome to page two
After the command line prints "hello ", it waits for the user response. if the user hits enter, instead of continuing to label "two", the command line closes.
Why?
Thanks.
Thats because it exits when the script comes to and end and has nothing more to do.
Add for example a pause at the very end of your script
Like this
echo. welcome to page two
pause
Then all you want on "page two" will be between your welcome to page two and pause
You don't say whether you are executing that batch from the prompt or from a shortcut"
After showing hello names entered the batch stops at the pause, and waits for an Enter. The >nul suppresses the prompt Press any key to continue . . .
batch will then continue to :two (the goto is redundant) but if you executed the routine from a "shortcut" the batch window will appear to close immediately as reaching end-of-file terminates the routine.
I made a simple LAN chat batch file, and i would like to know if
there is an command that checks if a specific txt file is updated.
The chat history is stored in log.dat and i want to have a sound notification or something like that when theres a new message.
#echo off
title LAN chat reader
call Color.bat
:read
call Color.bat
cls
type log.dat
timeout /t 3 /nobreak >nul
goto read
(im a noob, please tell me if this is possible)
To check the file date/time use for and %%~t prefix:
#echo off
title LAN chat reader
setlocal enableDelayedExpansion
:read
call Color.bat
cls
type log.dat
for %%a in (log.dat) do set filetimesize=%%~tza
:checkupdate
ping -n 1 -w 100 localhost >nul
for %%a in (log.dat) do if "!filetimesize!"=="%%~tza" goto checkupdate
echo updated
goto read
wOxxOm already gave a solution to check for an updated file.
Here is a way to produce a Sound:
copy con bell.txt
Then press the ALT-key enter 007 while keeping ALT pressed, then release the ALT key. ^G should appear on your Screen (= 0x07, which is a Bell), then press Ctrl-Z. This gives you a textfile with lenght = 1 Byte
Type bell.txt
will then beep.
EDIT an easier way to produce bell.txt: on commandline, enter echo ^G>bell.txt (to produce ^G press CTRL-G). This will create a three-byte-file (instead of the one-byte-file with the copy trick) (but that's only a line feed and should not disturb).
I made a simple batch chat that write the message to an txt file.
I need help with print the file every time it changed and with hidding output.
I used the type, delay and cls to print the file but it didnt work, it didnt printed the file.
launcher.bat:
start cmd /k
call room.bat
call chat.bat
using the launcher photo
room.bat(the problem):
:chat1
cls
TYPE room.txt
timeout /t 0.5
goto chat1
chat.bat(working but show extra info about the os and the file):
#echo off
cls
set D=%Date%
cls
echo enter your name
SET /P name=[name]
pause
:room
cls
SET /P chatpublic=[everyone]
SET "
echo %name%: %chatpublic% |%D%|>> room.txt
pause
goto room
without the launcher photo
Here's the culprit:
echo %name%: %chatpublic% |%D%|>> room.txt
That's because the | vertical line has a special meaning in Windows command line interpreter: commandA | commandB: pipe the output from commandA into commandB.
If you do want use a | vertical line in another sense (e.g. display it with an echo command), then you should escape it as follows:
echo %name%: %chatpublic% ^|%D%^|>> room.txt
I am looking for a way to place the cursor between several lines of echo commands so it appears that the pause is in the center of the code, rather than at the end, while still displaying the last line of text and not continuing to the next label until hitting anykey. is this possible?
I want to have the appearance that the last line of actual text is a footer, seperat from the above text.
At the moment, my sequencing looks similar to this:
:LABEL
CLS
ECHO text1
ECHO.
ECHO.
(want the PAUSE to appear here)
ECHO.
ECHO.
ECHO text2
PAUSE (while the PAUSE is really here to prevent text2 from being lost)
GOTO OTHERLABEL
Thanks a bunch!
I think I know what you are asking, correct me if I am wrong. You want this functionality:
echo hello
pause
echo bye
But you want to switch the location on the screen of the pause and echo bye. If so, that is not easy. I suppose you could use a vbscript that once the first pause runs in the above code, would send a key to the batch file, which would echo. a ton of times and then pause again, and then the vbscript could scroll up in the batch file. It's not worth it.