Skip to content

Instantly share code, notes, and snippets.

@fairjm
Last active September 8, 2015 11:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fairjm/d6810b1cb82ef1a64af4 to your computer and use it in GitHub Desktop.
Save fairjm/d6810b1cb82ef1a64af4 to your computer and use it in GitHub Desktop.
cmd wrapper
open System
open System.Text
open System.IO
open System.Diagnostics
let newProcess = new Process()
newProcess.StartInfo.FileName <- "cmd.exe"
newProcess.StartInfo.CreateNoWindow <- true
newProcess.StartInfo.UseShellExecute <- false
newProcess.StartInfo.RedirectStandardInput <- true
newProcess.StartInfo.RedirectStandardOutput <- true
newProcess.StartInfo.RedirectStandardError <- true
newProcess.OutputDataReceived.AddHandler(
new DataReceivedEventHandler(
fun (sender:obj)(line:DataReceivedEventArgs) ->
printfn "%s" line.Data))
newProcess.ErrorDataReceived.AddHandler(
new DataReceivedEventHandler(
fun (sender:obj)(line:DataReceivedEventArgs) ->
printfn "%s" line.Data))
newProcess.Start() |> ignore
newProcess.BeginOutputReadLine()
newProcess.BeginErrorReadLine()
let writer = newProcess.StandardInput
let rec loop () =
let i = Console.ReadLine()
writer.WriteLine(i)
if i.Trim() <> "exit" then
loop ()
loop()
writer.Close()
newProcess.Close()
printfn "exits"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment