使用Rebol将二进制数据打印到stdout

普史密斯

我正在使用Rebol产生二进制输出,但是输出不是我期望的。这是一个简单的测试脚本,它打印从0到255的所有字节:

REBOL[]
for i 0 255 1 [
  prin to char! i
]

像这样执行测试: rebol -q test.rebol | hexdump -v

使用Rebol 2.7时,输出会丢失00字节,但其他所有字节都可以:

0000000 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10
0000010 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20
...
00000e0 e1 e2 e3 e4 e5 e6 e7 e8 e9 ea eb ec ed ee ef f0
00000f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb fc fd fe ff
00000ff

使用Rebol 3(r3-g25033f8),第一个128字节就可以了,但其余所有字节都已更改,似乎Rebol3将输出视为UTF-8。

0000000 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f
0000010 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f
...
0000060 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f
0000070 70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e 7f
0000080 c2 80 c2 81 c2 82 c2 83 c2 84 c2 85 c2 86 c2 87
0000090 c2 88 c2 89 c2 8a c2 8b c2 8c c2 8d c2 8e c2 8f
...
0000160 c3 b0 c3 b1 c3 b2 c3 b3 c3 b4 c3 b5 c3 b6 c3 b7
0000170 c3 b8 c3 b9 c3 ba c3 bb c3 bc c3 bd c3 be c3 bf
0000180

有什么方法可以使用Rebol将二进制数据打印到标准输出吗?

德拉贡

在Rebol 2中,您可以write-io无损地写入到STDOUT之类的端口。

因此,您的示例如下所示:

Rebol []

for i 0 255 1 [
    write-io system/ports/output to-string to char! i 1
]

Rebol 3没有write-io,而是使用,write因此理论上您的示例应如下所示:

for i 0 255 1 [
    write system/ports/output to-string to char! i
]

不幸的是,此刻system/ports/output在Rebol 3中不起作用:(

$ r3

>> probe system/ports/input
make port! [
    spec: make object! [
        title: "Console Access"
        scheme: 'console
        ref: [scheme: 'console]
        path: none
    ]
    scheme: make object! [
        name: 'console
        title: "Console Access"
        spec: none
        info: none
        actor: make native! [[port!]]
        awake: none
    ]
    actor: make native! [[port!]]
    awake: none
    state: #{}
    data: none
    locals: none
]

;;  Good news is that STDIN is defined but...

>> probe system/ports/output
none
== none

;; bad news is that STDOUT isnt :(

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章