Closed callmekohei closed 6 years ago
Hello again! I'm callmekohei
!
So, I can do it!
Thank you (^_^)/
( code )
namespace Mono.Debugger.Client.Commands
#r "/usr/local/lib/sdb/sdb.exe"
#r "/usr/local/lib/sdb/Mono.Debugging.dll"
#r "/usr/local/lib/sdb/Mono.Debugging.Soft.dll"
open Mono.Debugger.Client
open Mono.Debugging.Client
open System
open System.IO
module Foo =
let gatherOutput f args =
try
// Switch MemoryStream
let ms = new MemoryStream()
let sw = new StreamWriter(ms)
let tw = TextWriter.Synchronized(sw)
sw.AutoFlush <- true
Console.SetOut(tw)
f args
// read data from MemoryStream
let sr = new System.IO.StreamReader(ms)
let mutable tmp = int64 0
let mutable flg = true
while flg = true do
// wait for output
System.Threading.Thread.Sleep 50
if tmp = int64 0 then
tmp <- ms.Position
else
if tmp = ms.Position then
flg <- false
else
tmp <- ms.Position
ms.Position <- int64 0
let rtn = sr.ReadToEnd()
// Switch StandardOut
let std = new StreamWriter(Console.OpenStandardOutput())
std.AutoFlush <- true
Console.SetOut(std)
rtn
with e -> e.Message
let run args =
try
Debugger.Run(new FileInfo(args))
with e -> Log.Info(e.Message)
type MyRun() =
inherit Command()
override __.Names = [|"run"|]
override __.Summary = ""
override __.Syntax = ""
override __.Help = ""
override __.Process(args) =
Log.Info("-----------------")
Log.Info( gatherOutput run args )
Log.Info("-----------------")
[<Sealed; Command>]
type MyCommand() =
inherit MultiCommand()
do base.AddCommand<MyRun>()
override this.Names = [|"mycmd"|]
override this.Summary = ""
override this.Syntax = ""
override this.Help = ""
Hello, I'm
callmekohei
!Problem
code
I'm happy to have a tip (^_^)/