add a timeout and a ctrl+c to a .bat file


   I have a command I run from a cmd window on my server, after 10 min, I usually give it a "ctrl+c' to cancel that command (it immediately goes back to the prompt as its a java program I am running).  After it stops, I start it up again for another 10 min.  I would like to automate this in a .bat file with a timeout and a ctrl+c.

Here is my command I run:

java -jar d:\dcm4che14\bin\dcmsnd.jar --poll-dir=d:\hold\ dicom://myserver:DCMSND@localhost:104

after the command runs for about 10 min I need to let the receiving application time to process what it has been sent and close the association and then I can start up the whole process again.  So, this .bat file would be an infinite loop essentially.  So, here is what I need it to do again:

1)  run the command:  
java -jar d:\dcm4che14\bin\dcmsnd.jar --poll-dir=d:\hold\ dicom://myserver:DCMSND@localhost:104
2)  wait 10 minutes after running it
3)  give it a ctrl+c to stop the java command
4)  run the command again
5) wait 10 minutes after running it
6) ctrl+c
7) run the command again
8) -- I think you get the idea

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Maen Abu-TabanjehNetwork Administrator, Network ConsultantCommented:
here is useful link with pause x time using dos
Paul TomasiCommented:
I don't think the CTR-C bit can be done... even stuffing CTRL-C into the keyboard buffer in assembler would only apply to the DOS session itself and not the java program.

I could be wrong on this as it's something I personally have not come across however, I can see it's usefulness in some circumstances such as run-away programs etc.

it might be easier to modify your java program to self-abort after a certain time has elapsed or a certain number of iterations or indeed, when some other condition is met.

It sounds like your java program monitors something while sending output to a file... it also sounds like you want the process interrupted to allow the system to regain control of the file and to process it's contents. It might also be the case you want the process to actually restart rather than just suspend itself for a while.

is it possible to have a look at your java app?

can you explain what it is you are doing as there may be a way to do it using just DOS and batch file language. this would simplify your task.
Just a crazy idea. What if the java app is wapped in an EXE. Then instead of "ctrl+c", you would taskkill it. Would that work?
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

Paul TomasiCommented:
Yep... Taskkill would do it if the java app is run as a task. It would have to be converted to an executable program (EXE) though.

The only other uncertainty is how that would effect any files that are open at the time you kill the task...

It's gonna be a case of try-and-see.

A quick search on the net reveals a wide choice of converters. Some free, some not. Here's the first 2 links in my browser:

Bill PrewCommented:
Have you looked in to the windows task scheduler?  I believe you can set a max run time of a scheduled job, and it will kill it when that is reached, in your case 10 minutes.  And you could have the job scheduled to run every 10 minutes, or every 11 minutes to avoid any overlap.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
doc_jayAuthor Commented:
thanks - I'll give the task sched a try -- good idea.
Good idea indeed!!
You can try this:
it depends on make your computer poing fake IP for many times, and then you can use taskkill command in the cmd.
You can repeat it as you want.
Steve KnightIT ConsultancyCommented:
i originally thought of idea like above but didn't think appropriate in this case as too easy to have the window stop for some reason etc.

I like Bill's suggestion of using task scheduler and have used the same myself in the past - either using the maximum time to run or a taskkill command at the start of the batch to remove any current instances.

In which case I guess it needs to schedule every 20 minutes and maximum run time of 10 mins.

a customer has a java based system running that needs restarting occasionally so would be interested in your outcome here...

doc_jayAuthor Commented:
it turned out that I didn't need to run that java app with that option - I was able to run it on a different PC win WinXP.  I was unable to make the app run correctly on 2008 server.  Now I am just running a .bat file to move my files to my WINXP machine and I have the same java app, just poll a directory and it will function as long as there are files in the folder.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft DOS

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.