Need help regarding Async and fsi

Posted by Stringer Bell on Stack Overflow See other posts from Stack Overflow or by Stringer Bell
Published on 2010-04-15T21:39:11Z Indexed on 2010/04/15 21:43 UTC
Read the original article Hit count: 323

Filed under:
|
|

I'd like to write some code that runs a sequence of F# scripts (.fsx). The thing is that I could have literally hundreds of scripts and if I do that:

let shellExecute program args =
    let startInfo = new ProcessStartInfo()
    do startInfo.FileName        <- program
    do startInfo.Arguments       <- args
    do startInfo.UseShellExecute <- true
    do startInfo.WindowStyle     <- ProcessWindowStyle.Hidden

    //do printfn "%s" startInfo.Arguments 
    let proc = Process.Start(startInfo)
    ()

scripts
|> Seq.iter (shellExecute "fsi")

it could stress too much my 2GB system. Anyway, I'd like to run scripts by batch of n, which seems also a good exercise for learning Async (I guess it's the way to go).

I have written some code and unfortunately it doesn't work:

open System.Diagnostics

let p = shellExecute "fsi" @"C:\Users\Stringer\foo.fsx"

async {
    let! exit = Async.AwaitEvent p.Exited
    do printfn "process has exited"
}
|> Async.StartImmediate

foo.fsx is just a hello world script.

I'd like also to figure out if it's doable to retrieve a return code for each executing script and if not, find another way. Thanks!

© Stack Overflow or respective owner

Related posts about F#

Related posts about f#-interactive