Wednesday 19 September 2012

Capting all console output

Do you remember this post?
Well, there is another way to copy all console output in a file:

echo: func [
    "Copies console output to a file."
    [catch]
    target [file! none! logic!]
    /append
][
    if port? system/ports/echo [
        close system/ports/echo
        system/ports/echo: none
    ]
    if target = true [target: %rebol-echo.txt]
    if file? target [
        system/ports/echo: throw-on-error [
            either not append [
                open/write/new/direct target
            ] [
                target: open/direct target
                skip target 4294967295 ; highest int should move to the end
                target
          ]
        ]
    ]
]


Just launch

echo %my_file.txt

and you'll obtain all console output in your file.
Don't you believe me?
Try:

echo %my_file.txt
? print
? append
editor read %my_file.txt

2 comments:

  1. You can capture also console output in a string for later processing, see: http://www.rebol.org/view-script.r?script=capture.r

    ReplyDelete
  2. Thank you. I was about to write a comment suggesting that you explain why this works. But first, I stared at it, and stared at it, and tried it, and looked at some "help" screens, and, suddenly, I UNDERSTOOD it. Big day for me.

    ReplyDelete