This page is no longer maintained — Please continue to the home page at www.scala-lang.org

fork-exec *nix process from scala

5 replies
Meredith Gregory
Joined: 2008-12-17,
User offline. Last seen 42 years 45 weeks ago.
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$


--
L.G. Meredith
Managing Partner
Biosimilarity LLC
806 55th St NE
Seattle, WA 98105

+1 206.650.3740

http://biosimilarity.blogspot.com
Samuel Robert Reid
Joined: 2008-12-17,
User offline. Last seen 1 year 22 weeks ago.
Re: fork-exec *nix process from scala

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$
>
>

Alex Boisvert
Joined: 2008-12-16,
User offline. Last seen 42 years 45 weeks ago.
Re: fork-exec *nix process from scala
See http://www.jroller.com/thebugslayer/entry/executing_external_system_commands_in

On Sun, Jan 4, 2009 at 11:15 AM, Meredith Gregory <lgreg [dot] meredith [at] gmail [dot] com> 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$


--
L.G. Meredith
Managing Partner
Biosimilarity LLC
806 55th St NE
Seattle, WA 98105

+1 206.650.3740

http://biosimilarity.blogspot.com

Lalit Pant
Joined: 2009-01-05,
User offline. Last seen 2 years 7 weeks ago.
Re: fork-exec *nix process from scala

I played quite a bit with this a few months ago (mainly on Windows XP, but
also on Ubuntu). Results here:
http://github.com/litan/scrisca/tree/master/src/main/scala/com/kogics/sc...

Looks like a lot of code in there ;). The core method to look at is
RichProcessBuilder.exec...

Cheers,
- Lalit
http://www.kogics.net

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$
>
>

Jim Miller
Joined: 2009-01-05,
User offline. Last seen 42 years 45 weeks ago.
Re: fork-exec *nix process from scala

I don't know about the command your executing but if the program
generates output you need to be consuming that output. At least under
Linux, the process will wait for the output buffer to be drained
before executing. If this is the case, start a thread that reads from
the Process InputStream while you're waiting for the command to be
executed.

On Sun, Jan 4, 2009 at 9:22 PM, Lalit Pant wrote:
>
> I played quite a bit with this a few months ago (mainly on Windows XP, but
> also on Ubuntu). Results here:
> http://github.com/litan/scrisca/tree/master/src/main/scala/com/kogics/sc...
>
> Looks like a lot of code in there ;). The core method to look at is
> RichProcessBuilder.exec...
>
> Cheers,
> - Lalit
> http://www.kogics.net
>
>
>
> 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$
>>
>>
>> --
>> L.G. Meredith
>> Managing Partner
>> Biosimilarity LLC
>> 806 55th St NE
>> Seattle, WA 98105
>>
>> +1 206.650.3740
>>
>> http://biosimilarity.blogspot.com
>>
>>
>
> --
> View this message in context: http://www.nabble.com/-scala--fork-exec-*nix-process-from-scala-tp212799...
> Sent from the Scala mailing list archive at Nabble.com.
>
>

Meredith Gregory
Joined: 2008-12-17,
User offline. Last seen 42 years 45 weeks ago.
Re: fork-exec *nix process from scala
All,

Many thanks for all your replies. i ended up wrapping this in actor goop and it worked. i'm not sure what was causing the blocking behavior i was seeing in other contexts, and unfortunately, don't have the cycles to track it down to minimal case.

On the other hand, i don't know the scala actor package at all and couldn't see an obvious way to get a non-polling form to get the results from the completed process. i wrote this truly god-awful-anathema-to-actors code to get the data out of the file it was dumped in by the forked process. You can see it here. If you've got any quick tips to avoid this mishigosh, i'm all ears.

Best wishes,

--greg

On Sun, Jan 4, 2009 at 6:46 PM, Jim Miller <gordon [dot] j [dot] miller [at] gmail [dot] com> wrote:
I don't know about the command your executing but if the program
generates output you need to be consuming that output.  At least under
Linux, the process will wait for the output buffer to be drained
before executing.  If this is the case, start a thread that reads from
the Process InputStream while you're waiting for the command to be
executed.

On Sun, Jan 4, 2009 at 9:22 PM, Lalit Pant <lalit_pant [at] yahoo [dot] com> wrote:
>
> I played quite a bit with this a few months ago (mainly on Windows XP, but
> also on Ubuntu). Results here:
> http://github.com/litan/scrisca/tree/master/src/main/scala/com/kogics/scrisca/proc/Process.scala
>
> Looks like a lot of code in there ;). The core method to look at is
> RichProcessBuilder.exec...
>
> Cheers,
> - Lalit
> http://www.kogics.net
>
>
>
> 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$
>>
>>
>> --
>> L.G. Meredith
>> Managing Partner
>> Biosimilarity LLC
>> 806 55th St NE
>> Seattle, WA 98105
>>
>> +1 206.650.3740
>>
>> http://biosimilarity.blogspot.com
>>
>>
>
> --
> View this message in context: http://www.nabble.com/-scala--fork-exec-*nix-process-from-scala-tp21279953p21284430.html
> Sent from the Scala mailing list archive at Nabble.com.
>
>



--
L.G. Meredith
Managing Partner
Biosimilarity LLC
806 55th St NE
Seattle, WA 98105

+1 206.650.3740

http://biosimilarity.blogspot.com

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland