0

is there a way to delay a batch without running a app to cause the delay?

i did a program that monitor the creation of a file, and it need to rescan the file size every second, so i need to make a 1 second delay

but in some machines, antivirus and programs installed by banks cause the delay program to freeze and don't exit properly.

choice, sleep, timeout, ping, all are external apps.

is there a internal command that can delay 1 second without running any app, besides internal CMD command? creating loops is not a option, cause it will consume CPU (my app is a converter, so cannot consume CPU while wait...)

thanks in advance ;)

  • It sounds like you're using the wrong tool for the wrong job. Normally you would monitor file system change events, and react based on that ([see this](http://stackoverflow.com/q/3517460/660921)). – Martin Tournoij Mar 13 '16 at 02:30
  • i understand i can use or make a proper tool, but in a batch is much more simple, cause is a simple process. i just need to get the filesize info every second, and after a quick calculation, estimate a percentage based on file size. to make a "proper" tool for this would be way overkill and beyond my capabilities... a simple delay would suffice... – Marlon Martins Mar 13 '16 at 02:43
  • If you need to ask a Stack Overflow question about it, then it's not *that* simple, is it :p The thing with batch scripts is that it's really easy to quickly clobber something together, but sooner or later (and usually sooner rather than later in my experience) you're going to run into limits and you need to bend over backwards to do something simple ... like waiting for a second :-) You could try using PowerShell, by the way, but that's only shipped with Windows 7/Server 2008R2 and newer by default, so may not be an option for you if some customers still use XP (it does run on XP though). – Martin Tournoij Mar 13 '16 at 02:49
  • I defy you to find a version of Windows where ping is an "external resource." – SomethingDark Mar 13 '16 at 05:41
  • 1
    what do you consider for internal command. Commands in [this list](http://ss64.com/nt/syntax-internal.html)? Or commands packed with windows in system32 directory? – npocmaka Mar 13 '16 at 09:28
  • @SomethingDark: external apps, not resources. like, "dir" is a internal command, ping is an application in system directory (ping.exe). – Marlon Martins Mar 13 '16 at 22:12
  • @npocmaka: yes, in that list. – Marlon Martins Mar 13 '16 at 22:13
  • Did... did you delete the system32 directory by accident or something? – SomethingDark Mar 13 '16 at 22:26
  • @SomethingDark: more probably it's the `%path%` variable. – Stephan Mar 14 '16 at 06:23

3 Answers3

2

is there a internal command that can delay 1 second without running any app, besides internal CMD command? creating loops is not a option, cause it will consume CPU (my app is a converter, so cannot consume CPU while wait...)

Answer - NO, not possible. There aren't many internal commands, and certainly none that can add a delay that does not consume CPU.

dbenham
  • 127,446
  • 28
  • 251
  • 390
0

>nul type "some file with about 60MB" - it even hasn't to be a textfile (I tried with a .mp4)

type is an internal command and so it meets your requirement. Although I'm not sure, if it "consumes no CPU time" ;)

By the way: I doubt, you can write a useful programm using only internal commands.

Stephan
  • 53,940
  • 10
  • 58
  • 91
  • Interesting idea, but surely it must consume CPU, plus it must be dependent on speed of disk drive, as well as other competing IO activity – dbenham Mar 13 '16 at 13:32
  • yes, of course it's using CPU time (see the `;)` in my post?). Also the time might be unexpectedly short on a server with a RAIDcontroller or on a system with a SSD. That's why `timeout` & co exist. – Stephan Mar 14 '16 at 06:21
  • Nope, your humor was a bit too subtle for me. I missed the `;)` and only saw the *"Im not sure"* – dbenham Mar 14 '16 at 14:52
0

Well, it's almost IMPOSSIBLE. But, if you try hard i think that a call and start can help you. here is the example:

Lets call the program need to wait batch1.bat

call "batch2.bat"

And place at the batch2.bat:

call "batch1.bat"

Then do this in loop of few moments.. You easily can do a loop with a variable. Hope I helped you!

Yoav Grinberg
  • 37
  • 1
  • 4