- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Re: fork-exec *nix process from scala
Sun, 2009-01-04, 20:27
Sam,
Thanks for your thoughts. i need to know when the process is finished. The trouble is the process is finished nearly instantaneously; but whatever thread is waiting on the waitFor is blocked indefinitely. i was merely illustrating this difficulty with the scala repl.
Best wishes,
--greg
On Sun, Jan 4, 2009 at 11:22 AM, Samuel Robert Reid <Reids@colorado.edu> wrote:
Thanks for your thoughts. i need to know when the process is finished. The trouble is the process is finished nearly instantaneously; but whatever thread is waiting on the waitFor is blocked indefinitely. i was merely illustrating this difficulty with the scala repl.
Best wishes,
--greg
On Sun, Jan 4, 2009 at 11:22 AM, Samuel Robert Reid <Reids@colorado.edu> wrote:
The process is forked when you exec(). When you call waitFor(), this is causing the blocking (like a join()). You could skip calling waitFor, or do the exec+waitFor in a new Thread (or with an Actor) if you need to know when it's finished.
Sam Reid
Meredith Gregory wrote:
Scalads and Lasses,
Anybody have any tips for exec'ing a *nix process from scala? The following blocks indefinitely.
Best wishes,
--greg
scala> Runtime.getRuntime().exec( "dot -Tsvg phred.dot -o phred" + (System.currentTimeMillis) + ".svg" )
res1: java.lang.Process = java.lang.UNIXProcess@1e0b6a
scala> res1.waitFor
C-c C-cres4: Int = 0
scala> bash-3.2$
Sun, 2009-01-04, 23:37
#2
Re: fork-exec *nix process from scala
Meredith Gregory wrote:
> Sam,
>
> Thanks for your thoughts. i need to know when the process is finished.
> The trouble is the process is finished nearly instantaneously; but
> whatever thread is waiting on the waitFor is blocked indefinitely. i was
> merely illustrating this difficulty with the scala repl.
You might want to close the stream going to the child process' stdin,
and start other threads to consume and close the streams for stdout /
stderr.
On Sun, Jan 04, 2009 at 11:26:13AM -0800, Meredith Gregory wrote:
> Thanks for your thoughts. i need to know when the process is finished. The
> trouble is the process is finished nearly instantaneously; but whatever
> thread is waiting on the waitFor is blocked indefinitely. i was merely
> illustrating this difficulty with the scala repl.
Are you sure the process is finished? It works for me (I'm on osx.)
$ cat ./foo
#!/bin/bash
#
sleep 5
echo "done"
$ scala27
Welcome to Scala version 2.7.2.final (Java HotSpot(TM) Client VM, Java 1.5.0_16).
Type in expressions to have them evaluated.
Type :help for more information.
scala> Runtime.getRuntime().exec("./foo")
res0: java.lang.Process = java.lang.UNIXProcess@7e5e84
scala> res0.waitFor
[5 seconds pass]
res1: Int = 0