Link to home
Start Free TrialLog in
Avatar of doc_jay
doc_jay

asked on

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

Hi,

   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

thanks!!
Avatar of Maen Abu-Tabanjeh
Maen Abu-Tabanjeh
Flag of Jordan image

here is useful link with pause x time using dos

http://www.robvanderwoude.com/wait.php
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.
@Paul
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?
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:

http://www.deluxe-directory.com/java2exe.html
http://gcc.gnu.org/java/

ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of doc_jay
doc_jay

ASKER

thanks - I'll give the task sched a try -- good idea.
Good idea indeed!!
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of doc_jay

ASKER

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.

thanks