Working with IFsiSessions
Creating sessions
ScriptHost.CreateNew()
and ScriptHost.Create()
provide several optional parameters
to configure the scripting environment:
-
fsiObj: obj
: The optional "fsi" object to use (defaults to using the one defined inFSharp.Compiler.Service.dll
) You should have the same members as https://github.com/Microsoft/visualfsharp/blob/fsharp4/src/fsharp/fsiaux.fsi#L19 . All your members are called via reflection. -
reportGlobal: bool
: When true all error messages and outputs contain the complete output (instead of only the output of the last command). This only affects error messages. Defaults tofalse
-
outWriter: TextWriter
: A custom TextWriter object where we additionally write the stdout of the executing code (for long running scripts). -
fsiOutWriter: TextWriter
: A custom TextWriter object where we additionally write the fsi stdout (for long running scripts). -
errWriter: TextWriter
: A custom TextWriter object where we additionally write the stderr of the executing code (for long running scripts). -
fsiErrWriter: TextWriter
: A custom TextWriter object where we additionally write the fsi stderr (for long running scripts). -
preventStdOut: bool
: A value indicating whether we should completly block the executing script from writing to the current stdout and stderr. Defaults tofalse
.
You should use preventStdOut = true
if you want to control the script output yourself.
You can work with either the live output or with the return values.
Return values will be constant no matter the configuration options!
Example usage ("Live Output"):
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: |
|
The standard output is:
|
Example usage ("Return values"):
1: 2: 3: 4: 5: 6: 7: 8: 9: |
|
The standard output is:
|
The value v is:
|
Example usage ("Use both"):
Note that you can use both systems at the same time as well (the return values are always available).
1: 2: |
|
The standard output is:
|
The value b is:
|
namespace Yaaf
namespace Yaaf.FSharp
namespace Yaaf.FSharp.Scripting
val liveSession : IFsiSession
Full name: IntroExamples.liveSession
Full name: IntroExamples.liveSession
type ScriptHost =
private new : unit -> ScriptHost
static member Create : opts:FsiOptions * ?fsiObj:obj * ?reportGlobal:bool * ?outWriter:TextWriter * ?fsiOutWriter:TextWriter * ?errWriter:TextWriter * ?fsiErrWriter:TextWriter * ?preventStdOut:bool -> IFsiSession
static member CreateForwardWriter : f:(string -> unit) * ?revertRedirect:bool * ?removeNewLines:bool -> TextWriter
static member CreateNew : ?defines:string list * ?fsiObj:obj * ?reportGlobal:bool * ?outWriter:TextWriter * ?fsiOutWriter:TextWriter * ?errWriter:TextWriter * ?fsiErrWriter:TextWriter * ?preventStdOut:bool -> IFsiSession
Full name: Yaaf.FSharp.Scripting.ScriptHost
private new : unit -> ScriptHost
static member Create : opts:FsiOptions * ?fsiObj:obj * ?reportGlobal:bool * ?outWriter:TextWriter * ?fsiOutWriter:TextWriter * ?errWriter:TextWriter * ?fsiErrWriter:TextWriter * ?preventStdOut:bool -> IFsiSession
static member CreateForwardWriter : f:(string -> unit) * ?revertRedirect:bool * ?removeNewLines:bool -> TextWriter
static member CreateNew : ?defines:string list * ?fsiObj:obj * ?reportGlobal:bool * ?outWriter:TextWriter * ?fsiOutWriter:TextWriter * ?errWriter:TextWriter * ?fsiErrWriter:TextWriter * ?preventStdOut:bool -> IFsiSession
Full name: Yaaf.FSharp.Scripting.ScriptHost
static member ScriptHost.CreateNew : ?defines:string list * ?fsiObj:obj * ?reportGlobal:bool * ?outWriter:System.IO.TextWriter * ?fsiOutWriter:System.IO.TextWriter * ?errWriter:System.IO.TextWriter * ?fsiErrWriter:System.IO.TextWriter * ?preventStdOut:bool -> IFsiSession
static member ScriptHost.CreateForwardWriter : f:(string -> unit) * ?revertRedirect:bool * ?removeNewLines:bool -> System.IO.TextWriter
val printfn : format:Printf.TextWriterFormat<'T> -> 'T
Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.printfn
Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.printfn
Multiple items
type FsiEvaluationException =
inherit Exception
new : info:SerializationInfo * context:StreamingContext -> FsiEvaluationException
new : msg:string * input:string * args:string list option * result:InteractionResult * inner:Exception -> FsiEvaluationException
val private result: InteractionResult
val private input: string
val private arguments: string list option
override GetObjectData : info:SerializationInfo * StreamingContext -> unit
override ToString : unit -> string
member Input : string
member Result : InteractionResult
Full name: Yaaf.FSharp.Scripting.FsiEvaluationException
--------------------
new : info:System.Runtime.Serialization.SerializationInfo * context:System.Runtime.Serialization.StreamingContext -> FsiEvaluationException
new : msg:string * input:string * args:string list option * result:InteractionResult * inner:System.Exception -> FsiEvaluationException
type FsiEvaluationException =
inherit Exception
new : info:SerializationInfo * context:StreamingContext -> FsiEvaluationException
new : msg:string * input:string * args:string list option * result:InteractionResult * inner:Exception -> FsiEvaluationException
val private result: InteractionResult
val private input: string
val private arguments: string list option
override GetObjectData : info:SerializationInfo * StreamingContext -> unit
override ToString : unit -> string
member Input : string
member Result : InteractionResult
Full name: Yaaf.FSharp.Scripting.FsiEvaluationException
--------------------
new : info:System.Runtime.Serialization.SerializationInfo * context:System.Runtime.Serialization.StreamingContext -> FsiEvaluationException
new : msg:string * input:string * args:string list option * result:InteractionResult * inner:System.Exception -> FsiEvaluationException
val e : FsiEvaluationException
val printf : format:Printf.TextWriterFormat<'T> -> 'T
Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.printf
Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.printf
property FsiEvaluationException.Result: InteractionResult
InteractionResult.Error: OutputData
OutputData.Merged: string
val reraise : unit -> 'T
Full name: Microsoft.FSharp.Core.Operators.reraise
Full name: Microsoft.FSharp.Core.Operators.reraise
member IFsiSession.EvalInteraction : s:string -> unit
val directSession : IFsiSession
Full name: IntroExamples.directSession
Full name: IntroExamples.directSession
val v : InteractionResult
Full name: IntroExamples.v
Full name: IntroExamples.v
abstract member IFsiSession.EvalInteractionWithOutput : string -> InteractionResult
InteractionResult.Output: OutputData
OutputData.ScriptOutput: string
val b : InteractionResult
Full name: IntroExamples.b
Full name: IntroExamples.b