Cursor in middle of text in batch - batch-file

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.

Related

Batch. Trying to make text adventure, if else not working

i am trying to make a text adventure, but i'm kind of clueless how to get an if/else statement to work with a variable. probably a few mistakes in my code:
# echo off
color 0a
echo This is a text adventure! to play, read through the story and at certain points you get to make decisions.
echo Remember, selecting an invalid option will automatically be counted as option 2!
echo have fun
pause
cls
echo You wake up in a dimly lit room. You can't seem to remember anything. Anything about you or how you got here, that is.
echo You walk towards the door. It is locked.
echo 1)Force the door open.
echo 2) look around for another means of escape.
set /p escape=
if %escape% = 1
cls
echo you get the door open, but an orc comes in and smashes your face.
echo get rekt buddy, game over.
pause
exit
else
goto dungeon
:dungeon
cls
echo well done.
pause
exit
If your if statement has has an accompanying else statement, you need to use parentheses. The else must also be in the format ) else (, like this:
# echo off
color 0a
echo This is a text adventure! to play, read through the story and at certain points you get to make decisions.
echo Remember, selecting an invalid option will automatically be counted as option 2!
echo have fun
pause
cls
echo You wake up in a dimly lit room. You can't seem to remember anything. Anything about you or how you got here, that is.
echo You walk towards the door. It is locked.
echo 1)Force the door open.
echo 2) look around for another means of escape.
set /p escape=
if "%escape%"=="1" (
cls
echo you get the door open, but an orc comes in and smashes your face.
echo get rekt buddy, game over.
pause
exit
) else (
goto dungeon
)
exit /b
:dungeon
cls
echo well done.
pause
exit
I've removed the blanks lines for aesthetic purposes; you can put them back in if you really want them. I also added a exit /b because having a goto followed by the label you're going to is bad form. The quotes in the if statement are there to prevent the script from breaking if the user enters nothing.

Batch file - stops in the middle of running

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.

how to detect change in .txt file using batch?

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).

bat file programmatically press enter to go next line

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

How can I open a file in Batch without focusing on it?

I'm using the start command to open a .mp3 or .wav file in wmplayer along with other certain events in a Batch program I'm writing. It works perfectly, and is accompanied by TASKKILL /IM wmplayer.exe to stop the program when the user goes to the next screen of the application. The only thing that could make it work more smoothly is if the program would open in the background, so the user doesn't have to click back into CMD. Is there any way to open the sound effect in wmplayer without switching focus over to wmplayer, and furthermore remaining selected into CMD? Thanks in advance.
You could have the original batch file open an alternate one after opening your wmplayer.exe to put the alternate on top. From there you could program the alternate to do all the same things your original file would do.
For example your main file's code could be:
#echo off
title Yourtitle
start wmplayer.exe
start AltBatch.bat
exit
And your alternate (AltBatch.bat):
#echo off
title YourTitle
:: (Your code here)
Or, simply put this would be the layered order on screen:
Original > wmplayer.exe > Alternate
So let me know if this code can did the trick or not ?
You just change the path of your sound !
#echo off
Title Playing sound on the background while executing some commands
set Soundfile=http://hackoo.alwaysdata.net/feeling.mp3
( echo Set Sound = CreateObject("WMPlayer.OCX.7"^)
echo Sound.URL = "%Soundfile%"
echo Sound.Controls.play
echo do while Sound.currentmedia.duration = 0
echo wscript.sleep 100
echo loop
echo wscript.sleep (int(Sound.currentmedia.duration^)+1^)*1000) >sound.vbs
start /min sound.vbs
ping www.google.com
ping www.stackoverflow.com
tracert www.google.com
tracert www.stackoverflow.com
pause

Resources