This repository has been archived by the owner on Nov 11, 2024. It is now read-only.
Stdout in sdb plugin #71
Answered
by
callmekohei
callmekohei
asked this question in
Questions
-
Hello, I'm Problem
code open Mono.Debugger.Client
open Mono.Debugging.Client
open System.IO
[<Sealed; Command>]
type MyCommand() =
inherit Command()
override __.Names = [|"mycmd"|]
override __.Summary = "aaa bbb ccc"
override __.Syntax = "ddd eee fff"
override __.Help = "Help Help Help"
override __.Process(args) =
Log.Info("-----------------")
/// I want to display app's stdout!
????
Log.Info("-----------------") I'm happy to have a tip (^_^)/ |
Beta Was this translation helpful? Give feedback.
Answered by
callmekohei
Feb 14, 2018
Replies: 1 comment
-
Hello again! I'm 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 = "" |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
alexrp
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello again! I'm
callmekohei
!So, I can do it!
Thank you (^_^)/
( code )