File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

who can my question about this code

 
lei feng
Greenhorn
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
lei feng
Greenhorn
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. if i only use process.waitFor(), the whole program will wait forever and never wake up and return.
2. but using this code the program only wait for the file have been moved. then run the next code? i don't know why?
3. the StreamGobbler as a thread. what is its function? i suppose this thread is why the waitFor() can return..but i don't know how does it get it?

who can answer me....thanks any help will be appreciate!
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The StreamGobbler threads read the stdout and errout of the command. They are on separate threads because we don't know when either or both of those streams will have data, if they ever do.

I'm not sure where you got StreamGobbler; there are several versions around the net. Does it display what it reads right away? Or store it up for later? Check and see if you are getting any messages from the command.

Does that whole command execute ok from a command window? Including the cmd.exe /C part?
 
lei feng
Greenhorn
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks you reply.I still want to figure out how it works to ensure when the proccess wait until the cmd finish. if i use move xxx xxx this cmd i don't get any message. but i try to use the dir cmd, i get the whole information from the cmd to the eclipse console...I'm going to check the code
 
lei feng
Greenhorn
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I get it the answer.
see the different result:

use this code, the process will wait until you stop it manually


this code will stop after the cmd finsh task.

the reason: use getRuntime.exec() will get a inpustream,if you don't read this inputstream in time. the process will lock. if you use waitFor() the whole process will lock,so you must read(clear) the inputstream to esure the process run.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic