REBOL 3.0

Stdio: a note about redirection in Windows

Carl Sassenrath, CTO
REBOL Technologies
27-Oct-2009 4:14 GMT

Article #0282
Main page || Index || Prior Article [0281] || Next Article [0283] || 11 Comments || Send feedback

Windows stdio redirection works in A93, but there are some things to know:

  1. In R3 the redirected stdin and stdout streams are UTF-8 encoded.
  2. In R3 the default console window is Unicode wide-char encoded.
  3. Do not mix the two modes.

For example, from a Command Prompt window, you can redirect output, or input and output:

> r3 -q test.r >output.txt

> r3 -q test.r <input.txt >output.txt

But, if you only redirect input:

> r3 -q test.r <input.txt

you're going to see a window pop up to handle any output. I've not found any way to solve this problem in Windows, nor do I find any information about it on the web. So, my advice is to redirect output as well.

Why?

The problem here comes from the fact that when running from a Command Prompt window, the handle returned by:

GetStdHandle(STD_OUTPUT_HANDLE)

is not valid for WriteFile(). Why? I cannot say. I researched it, but found no good explanation.

Of course, it's problematic anyway because you can't write UTF-8 to just any device in Windows. Windows is based on wide-char Unicode.

However, if you find the solution to this problem, let me know.

11 Comments

REBOL 3.0
Updated 16-Nov-2024 - Edit - Copyright REBOL Technologies - REBOL.net