, ( 9, ;) , ReadLine , , . OutputDataRecieved.
open System.Text
open System.Diagnostics
let shellEx program args =
let startInfo = new ProcessStartInfo()
startInfo.FileName <- program
startInfo.Arguments <- args
startInfo.UseShellExecute <- false
startInfo.RedirectStandardOutput <- true
startInfo.RedirectStandardInput <- true
let proc = new Process()
proc.EnableRaisingEvents <- true
let driverOutput = new StringBuilder()
proc.OutputDataReceived.AddHandler(
DataReceivedEventHandler(
(fun sender args -> driverOutput.Append(args.Data) |> ignore)
)
)
proc.StartInfo <- startInfo
proc.Start() |> ignore
proc.BeginOutputReadLine()
proc.StandardInput.WriteLine("let x = 1;;")
proc.StandardInput.WriteLine("x + x + x;;")
proc.StandardInput.WriteLine("#q;;")
proc.WaitForExit()
(proc.ExitCode, driverOutput.ToString())
( ):
val it : int * string =
(0,
"Microsoft F# Interactive, (c) Microsoft Corporation, All Rights ReservedF# Version 1.9.7.8, compiling for .NET Framework Version v2.0.50727For help type #help;;> val x : int = 1> val it : int = 3> ")