Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Ultimately I solved the problem by doing the following:</p> <ol> <li><p>Inside my program, for calling <code>adb start-server</code>, I no longer use <code>org.apache.commons.exec.DefaultExecutor.execute("adb start-server")</code> nor Java's <code>Runtime.getRuntime().exec("adb start-server")</code>.<br> Instead, I use <code>java.lang.ProcessBuilder("adb start-server").inheritIO().start().waitFor()</code>. Note the <code>inheritIO()</code> is added in Java 7 and allows for online reading of the started process stdout, among others.<br> <strong>EDIT</strong> The <code>inheritIO()</code> in Gradle has no effect when Gradle is called from CLI directly as opposed to being called by IntelliJ IDEA. See <a href="https://stackoverflow.com/questions/10671081/windows-java-child-process-doesnt-input-or-output-when-set-to-parents-standard">this question</a> for details. Probably implementing <code>StreamGobbler</code> as described <a href="http://www.javaworld.com/jw-12-2000/jw-1229-traps.html?page=4" rel="nofollow noreferrer">here</a> would fix the problem.</p></li> <li><p>In Gradle, instead of Gradle's <a href="http://www.gradle.org/docs/current/userguide/application_plugin.html" rel="nofollow noreferrer">application plugin</a>'s <code>run</code> task, I again use <code>ProcessBuilder</code> reusing <code>run</code> tasks variables. It looks like so:</p></li> </ol> <pre><code>apply plugin: 'java' apply plugin: 'application' sourceCompatibility = '1.7' targetCompatibility = '1.7' // configuration-time of the original run task run { main = com.example.MainClass; // without this, our custom run will try to run "null" } task myRun(dependsOn: build) { // execution-time of our custom run task. doFirst { ProcessBuilder pb = new ProcessBuilder(tasks['run'].commandLine); pb.directory(tasks['run'].workingDir); // works when the gradle command is executed from IntelliJ IDEA, has no effect when executed from standalone CLI interface. pb.inheritIO(); Process proc = pb.start(); proc.waitFor(); } } </code></pre> <p>As for the reason of the strange behaviors, I don't have any definite answer, so I refrain from further comments.</p> <p><strong>EDIT 9 July 2013</strong><br> <a href="https://stackoverflow.com/questions/931536/how-do-i-launch-a-completely-independent-process-from-a-java-program">This question</a> seems to point out the answer to Question 2 is: on windows, the parent process waits for child process before it terminates. Unfortunately, the solutions proposed there do not work because of problem stated in Question 1. </p> <p>Hope this helps,<br> Konrad</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload