Last active
September 8, 2015 11:42
-
-
Save fairjm/d6810b1cb82ef1a64af4 to your computer and use it in GitHub Desktop.
cmd wrapper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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