Java call Shell process has not exited

Source: Internet
Author: User
Tags call shell

*

http://kingj.iteye.com/blog/1420586

, there was

Java.lang.IllegalThreadStateException:process have not exited
At Java.lang.Win32Process.exitValue (Native Method)

Exception, background 100 degree discovery, the JDK implementation process, call External command is not synchronous call, but asynchronous execution. So the tree command returns without executing successfully, and the JDK throws an exception.

int Status=process.exitvalue ();

My solution is to use Thread.Sleep (1000) in front of this sentence;

Or

The reason is that the Exitvalue () method does not wait for the external process to end. If the external process is not finished, Exitvalue () will throw illegalthreadstateexception. The solution is to call the process's waitfor () method. The WAITFOR () method suspends the current thread until the external process finishes. Of course, using Exitvalue () or waitfor () depends entirely on your needs. You can set a Boolean flag to determine which one to use. Run the following code:

*

Java call Shell process has not exited

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.