Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > timing out after Runtime.getRuntime().exec(command)

Reply
Thread Tools

timing out after Runtime.getRuntime().exec(command)

 
 
Robert Mark Bram
Guest
Posts: n/a
 
      07-15-2005
Hi All,

I have some code like this:

Process pprocess = Runtime.getRuntime().exec(ftfCommand);
process.waitFor();

How do I make a timeout occur after x milliseconds?

Rob


 
Reply With Quote
 
 
 
 
Stefan Schulz
Guest
Posts: n/a
 
      07-15-2005
On Thu, 14 Jul 2005 23:41:03 -0700, Robert Mark Bram wrote:

> Hi All,
>
> I have some code like this:
>
> Process pprocess = Runtime.getRuntime().exec(ftfCommand);
> process.waitFor();
>
> How do I make a timeout occur after x milliseconds?


Warning: untested from the top of my head

void foo(String ftfCommand){
class Waker implements Runnable {
private Thread t;
Waker(Thread toWake){
t = toWake;
}
public void run(){
synchronized(this){
this.wait(TIMEOUT);
}

t.interrupt();
}
}

new Thread(new Waker(Thread.currentThread())).start();
Process pprocess = Runtime.getRuntime().exec(ftfCommand);

try {
pprocess.waitFor();
} catch (InterruptedException e){
// timed out
}

How do I make a timeout occur after x milliseconds?


--
You can't run away forever,
But there's nothing wrong with getting a good head start.
--- Jim Steinman, "Rock and Roll Dreams Come Through"


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Disabled Idle Timeouts, still timing out after 20 minutes =?Utf-8?B?U3RlZmFuIEJhcmxvdw==?= ASP .Net 8 08-22-2006 02:06 AM
PooledExecutor and timing tasks (before/after hooks)? OtisUsenet Java 0 04-28-2006 08:16 PM
Session timing out after 20 minutes Serge ASP .Net Security 0 04-13-2006 06:43 PM
Timing of updating labels and GridView after a SQLDataSource read Michael Kellogg ASP .Net 0 04-06-2006 08:19 PM
Wireless Connection Timing Out with XP SP2 =?Utf-8?B?QW5vdGhlckhpZ2dpbnM=?= Wireless Networking 0 12-16-2004 06:09 AM



Advertisments