io - 似乎无法从运行中获取非字符串输出

标签 io raku

I can't think of other way to run a command line that outputs binary files, so I'll have to go with this.

让我们将二进制文件添加到 git 存储库

mkdir test
cd test
git init .
wget https://upload.wikimedia.org/wikipedia/commons/thumb/8/85/Camelia.svg/320px-Camelia.svg.png
git add 320px-Camelia.svg.png
git commit -am "Added Camelia"

获取输出的提交哈希,我们将在下面使用它。

现在,运行这个:

say (run "git", "show", "<grabbed hash>:Camelia.svg.png", :out).out

这将返回一个Malformed UTF-8 消息。很公平,它不是二进制的。但是,我试图用 try 捕获该异常,但没有办法。我已经尝试将运行与 out 分开,但我仍然遇到无法捕获的异常。有什么想法吗?

最佳答案

:bin 选项传递给 run 以让它执行二进制 I/O。使用 curl 的示例:

$ raku -e 'say (run "curl", "--no-progress-meter", "https://raku.org/camelia-logo.png", :out, :bin).out.slurp'
Buf[uint8]:0x<89 50 4E 47 0D 0A 1A 0A 00 00 00 0D 49 48 44 52 00 00 01 05 00 00 00 F3 08 06 00 00 00 8F 2A 03 21 00 00 00 01 73 52 47 42 00 AE CE 1C E9 00 00 00 09 70 48 59 73 00 00 0F 61 00 00 0F 61 01 A8 3F A7 69 00 00 00 07 74 49 4D 45 07 D9 07 11 03 07 3A 28 6B FA 81 00 00 00 1A 74 45 58 74 43 6F 6D 6D 65 6E ...>

关于io - 似乎无法从运行中获取非字符串输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74166112/

相关文章:

java - Java中非阻塞写入的顺序

raku - 我什么时候可以使用任意星?

polymorphism - Perl 6 和 `multi method new`

c - 带有对齐堆栈缓冲区的 O_DIRECT IO 问题

c - C中的read函数只读取3072字节

java - 如何关闭 IO?

printing - raku REPL 在 WINdows 8 下的 `cygwin` 上似乎没有响应

raku - 为什么 100 ~~ ^100 在 Perl 6 中返回 false?

unit-testing - 如何在对模块进行单元测试时模拟导入的子例程

c# - 使用 C# 读取 PuTTY 输出