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."
    target [file! none! logic!]
    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

Just launch

echo %my_file.txt

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

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


  1. You can capture also console output in a string for later processing, see:

  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.