File: hosted.fsx

package info (click to toggle)
fsharp 3.1.1.26%2Bdfsg2-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 59,244 kB
  • ctags: 4,190
  • sloc: cs: 13,398; ml: 1,098; sh: 399; makefile: 293; xml: 82
file content (44 lines) | stat: -rw-r--r-- 1,252 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44


#r @"../../lib/release/4.0/FSharp.Compiler.dll"
#r @"../../lib/release/4.0/fsiAnyCpu.exe"

open Microsoft.FSharp.Compiler.Interactive.Shell

open System
open System.IO
open System.Collections.Generic

let stdinStream = new CompilerInputStream()
let stdin = new System.IO.StreamReader(stdinStream)


let stdoutStream = new CompilerOutputStream()
let stdout = StreamWriter.Synchronized(new System.IO.StreamWriter(stdoutStream, AutoFlush=true))

let stderrStream = new CompilerOutputStream()
let stderr = StreamWriter.Synchronized(new System.IO.StreamWriter(stderrStream, AutoFlush=true))

System.Console.SetOut stdout
System.Console.SetError stderr

stdinStream.Add("eprintfn \"writing to error\";;\n")
stdinStream.Add("printfn \"hello world to out\";;\n")
stdinStream.Add("let x = 1;;\n")
stdinStream.Add("eprintfn \"this is me on error, x = %d\" x;;\n\n")
stdinStream.Add("printfn \"this is me on out, x = %d\" x;;\n\n")
stdinStream.Add("let x = 1;;\n")

let session = FsiEvaluationSession([| "fsiAnyCpu.exe" |], stdin, stdout, stderr)

// Start the session in the background
async { do session.Run() } |> Async.Start

session.Interrupt()

// Wait a bit before executing these lines
let text1 = stdoutStream.Read()
let text2 = stderrStream.Read()