Sparsh Mittal <[email protected]> wrote on 02/11/2013 01:00:02 PM:
>
> Hello
> I am using the following program, with the aim of running external
> binary (in place of "sleep 500"). The problem is that after issuing
> Runtime.execForWrite, the control does not wait till the end of this
> command, which is not what I want. Can you suggest a way, so that I
> can make control wait till the  Runtime.execForWrite("Command")
> waits till end of   Command. Thanks.
>
> ===============================================
> import x10.io.Console;
> import x10.lang.Runtime;
>
> public class CheckForBlockingCommand {
>
>   public static def main(Array[String]) {
>     val TIMES: int = 10;
>     for(var k: Int =0; k< TIMES; k++) {
>     Console.OUT.println(" I am launching "+ k);
>     Runtime.execForWrite("sleep 500");
>     }
>       Console.OUT.println("Done!" );
>   }
> }
>
>

Hi,

        Runtime.execForWrite/Read fork a new process, but do not wait for the
forked process to complete before returning.  With the C++ backend of X10,
you can call close on the returned Writer to wait as shown below.  With the
Java backend of X10, this doesn't work (won't wait) due to API differences
between C and Java stdlibs  (it could be made to work in X10 by calling
waitFor on the java.lang.Process object returned from
java.lang.Runtime.exec, but that is not exposed at the X10 level.  You'd
have to tweak the Java code implementing the native method if you need this
on the Java backend of X10.

public class CheckForBlockingCommand {

public static def main(Array[String]) {
val TIMES: int = 10;
for(var k: Int =0; k< TIMES; k++) {
Console.OUT.println(" I am launching "+ k);
val t = Runtime.execForWrite("sleep 5");
t.close();
}
Console.OUT.println("Done!" );
}
}

--dave
------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013 
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________
X10-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/x10-users

Reply via email to