将未格式化的(二进制数据)写入标准输出 [英] Write unformatted (binary data) to stdout

查看:18
本文介绍了将未格式化的(二进制数据)写入标准输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 Fortran 90 程序中将未格式化的(二进制)数据写入 STDOUT.我正在使用 AIX Unix,不幸的是它不会让我以未格式化"的方式打开单元 6.我想我会尝试在不同的单元号下打开 /dev/stdout,但是 /dev/stdout 在 AIX 中不存在(尽管这种方法在 Linux 下有效).

I want to write unformatted (binary) data to STDOUT in a Fortran 90 program. I am using AIX Unix and unfortunately it won't let me open unit 6 as "unformatted". I thought I would try and open /dev/stdout instead under a different unit number, but /dev/stdout does not exist in AIX (although this method worked under Linux).

基本上,我想将我的程序输出直接通过管道传输到另一个程序中,从而避免使用中间文件,有点像 gzip -c 所做的那样.考虑到我在上面遇到的两个问题,还有其他方法可以实现吗?

Basically, I want to pipe my programs output directly into another program, thus avoiding having an intermediate file, a bit like gzip -c does. Is there some other way I can achieve this, considering the two problems I have encountered above?

推荐答案

我会尝试通过 TRANSFER() 将数据转换为长字符并使用非高级 i/o 打印它.问题将是您的处理器对记录长度的限制.如果它太短,您最终会在某处出现意外的记录结束标志.此外,您的处理器可能不会按照您希望的方式写入不可打印的字符.

I would try to convert the data by TRANSFER() to a long character and print it with nonadvancing i/o. The problem will be your processors' limit for the record length. If it is too short you will end up having an unexpected end of record sign somewhere. Also your processor may not write the unprintable characters the way you would like.

即,类似的东西

character(len=max_length) :: buffer

buffer = transfer(data,buffer)

write(*,'(a)',advance='no') trim(buffer)

我在无法打印的字符中看到的最大问题.另请参阅非高级 I/O 的惊喜

The largest problem I see in the unprintable characters. See also A suprise with non-advancing I/O

---编辑---另一种可能性,尝试使用文件 /proc/self/fd/1/dev/fd/1

---EDIT--- Another possibility, try to use file /proc/self/fd/1 or /dev/fd/1

测试:

open(11,file='/proc/self/fd/1',access='stream',action='write')
write(11) 11
write(11) 1.1
close(11)
end

这篇关于将未格式化的(二进制数据)写入标准输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆