• Post Reply Bookmark Topic Watch Topic
  • New Topic

start a file explorer in win and after 2 seconds "kill it" in java?  RSS feed

 
Niklas Karlsson
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I want so
open a fileexplorer (with a path)
and then close it after 2 seconds, how do i do this in java?

if i ude the bach in CMD this works to kill all :

but not in java :-(

the big problem is that if i only kill explorer.exe the shell
with the startmeny and so on is altso killed :-(

so the code (no try catch here but i have this on the "real code"..):


this program open the file explorer in the C:/folder
then wait some time then "nothing"!

but if I run this (see bellow) the fileexplorer closed but also win shell close :-(



:-(

(and then make this run when I have make a jar file on this)
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The first thing I notice is that you're calling waitFor() without making sure that the process' output buffers are cleared. you should read When Runtime.exec() won't. The article is old, but apart from not mentioning ProcessBuilder (using redirectErrorStream(true) can make life a bit easier) it's still very relevant.
 
Campbell Ritchie
Marshal
Posts: 56581
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A ProcessBuilder object can redirect the streams to make their emptying easier, but it has not changed the principles in the Daconta article which Rob gave you a link to.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!