rv1822
rv1822

Reputation: 169

How to stop tail -f command through java program?

I'm giving a tail -f command on a log file through java. When a certain string is found, I want to stop following the file and execute the rest of my code. How do I stop it using Java?

Thanks

Upvotes: 0

Views: 296

Answers (2)

GreyBeardedGeek
GreyBeardedGeek

Reputation: 30088

I know that this isn't a direct answer to your question, but using a native shell command probably isn't the best way to do this. In addition to the problem that you are experiencing, it makes the code non-portable.

Have a look at Apache's 'Tailer' class - see http://commons.apache.org/io/api-release/org/apache/commons/io/input/Tailer.html It has a stop() method.

Upvotes: 2

Joey
Joey

Reputation: 354586

Process.destroy() might help.

Upvotes: 0

Related Questions