如何将原始类型/字节写入stdout?

编程入门 行业动态 更新时间:2024-10-27 00:32:19
本文介绍了如何将原始类型/字节写入stdout?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在将原始类型输出到标准输出方面苦苦挣扎了很长时间. 这是我尝试过但未按预期方式工作的内容:

I am struggling for quite some time with outputting a raw type to standard output. Here is what I tried and did not work the desired way:

r <- as.raw(c(0x41, 0x00, 0x43)) # r = "A\0C" cat(rawToChar(r)) # displays warning and skips data after NULL (outputs "A") cat(r) # outputs "41 00 43" writeBin(r, stdout()) # error: can only write to binary connection

我正在寻找一种将所有三个字节/字符打印到stdout的方法.

I am looking for a way to get all three bytes / characters printed to stdout.

推荐答案

如果您使用的操作系统带有猫"或类似程序,我们可以将任意数据通过管道传输到stdout,如下所示:

If you are using an operating system that has a 'cat' or similar program, we can pipe arbitrary data to stdout like so:

con <- pipe("cat", "wb") writeBin(as.raw(c(0x41, 0x00, 0x43)), con) flush(con)

这一直是一个问题,特别是因为我们想将R用于通用网关接口(CGI).我认为没有更直接的途径,但是您可以查看 RApache 源代码,以了解sendBin功能已实现.

This has been an issue for some time, especially because we would like to use R for common gateway interface (CGI). I don't believe there is a more direct route, but you might look at the RApache source code, to see how the sendBin function is implemented.

更多推荐

如何将原始类型/字节写入stdout?

本文发布于:2023-10-24 09:23:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1523566.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字节   如何将   原始   类型   stdout

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!