Solved Use milliseconds instead of seconds in batch CHOICE command

January 13, 2016 at 14:12:51
Specs: Windows 10, X4 955 Black Edition | 8GB
I'm using "choice /d y /t 1 >nul" in this example
echo Hello world
choice /d y /t 1 >nul
echo Hello world 2
and the "choice /d y /t 1 >nul" is there to wait for 1 second but not show waiting in cmd and then show another echo, the thing that I wanted to do is make waiting less than 1 second, like half a second or even less, is that possible as the minimum value for /t is 0? Can I make it in milliseconds somehow? Thanks in advance!

EDIT: I'm quiet new to this stuff so don't go hard on me please :P

message edited by JustRelaxASC


See More: Use milliseconds instead of seconds in batch CHOICE command

Report •

✔ Best Answer
January 14, 2016 at 11:13:13
TIMEOUT or CHOICE are the commonly used ones for batch. You're not going to find something with millisecond precision for batch, because whatever you choose will have to spawn as a new process. That could take seconds, so finer precision isn't required, and would just be misleading.

This is different from other languages, as most of them implement a wait within the process running the script.

How To Ask Questions The Smart Way



#1
January 13, 2016 at 20:42:57
No. Depending on what your actual objective is, there might slim chance of a batch solution, but not using CHOICE. This sounds like a game scenario, since nothing else requires sub-second reaction time from the operator. Anyway, CHOICE won't do the job...

Report •

#2
January 14, 2016 at 06:56:24
I found out that ping
1.1.1.1 (random ip address) -n 1 -w *inster amount of milliseconds here* >nul
does the job that I initially wanted but it seems that it has a limited time of how low on milliseconds you can go, I've tryed putting 1ms and it takes same time as 500ms but 2000ms doesnt take same time as 500ms, it takes longer, so idk how can I make it even shorter than that time, I tried removing -n 1 and instead leaving -n only but that makes 2 echoes appear one after another just way too quick and -n 1 makes them appear a little bit slower than I want it to be, so idk if there is any other command I can use for delay between 2 echoes but to have full control over it?

Report •

#3
January 14, 2016 at 10:30:20
I've never liked using ping for delays, if just because relying on the network can cause the unexpected to happen if you ever go off-line.

I should probably point out that this is easier to handle in any of the other native scripting languages, and they're all easier than batch. If you're really a beginner, you should pick a better language. For instance, PowerShell'd look like this:

"Hello world"
Start-Sleep -Milliseconds 500
"Hello world 2"

How To Ask Questions The Smart Way


Report •

Related Solutions

#4
January 14, 2016 at 10:52:10
Thanks for the PowerShell suggestion! I will take a look into it

So if you are against using ping for delaying in batch, do you have any other method on how to do it in batch?

message edited by JustRelaxASC


Report •

#5
January 14, 2016 at 11:13:13
✔ Best Answer
TIMEOUT or CHOICE are the commonly used ones for batch. You're not going to find something with millisecond precision for batch, because whatever you choose will have to spawn as a new process. That could take seconds, so finer precision isn't required, and would just be misleading.

This is different from other languages, as most of them implement a wait within the process running the script.

How To Ask Questions The Smart Way


Report •

#6
January 15, 2016 at 00:16:53
Alright, thanks a lot!

Report •

Ask Question