stdout和/dev/stdout之间的区别 [英] Difference between stdout and /dev/stdout

查看:1025
本文介绍了stdout和/dev/stdout之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

bala@hp:~$ echo "Hello World" > stdout
bala@hp:~$ cat stdout
Hello World

bala@hp:~$ echo "Hello World" > /dev/stdout
Hello World

请澄清stdout/dev/stdout

注意:

bala@hp:~$ file stdout
stdout: ASCII text

bala@hp:~$ file /dev/stdout
/dev/stdout: symbolic link to `/proc/self/fd/1'

请帮助您了解区别.

推荐答案

在您的情况下

  • stdout是普通文件,在您运行命令的同一目录中创建.

  • stdout is a normal file, created in the same directory where you're running the command.

因此,当您将echo的输出重定向到stdout时,它将被写入文件.您需要执行cat(例如,您在此处所做的)才能在此处在屏幕上看到内容.

So, when you're redirecting the output of echo to stdout, it is written to the file. You need to do cat (as example, here you did) in order to see the content on screen here.

/dev/stdout 设备文件,这是/proc/self/fd/1的链接,这意味着它引用了当前进程保存的文件描述符1.

/dev/stdout is a device file, which is a link to /proc/self/fd/1, which means it is referring to the file descriptor 1 held by the current process.

因此,当您将echo的输出重定向到/dev/stdout时,它会直接发送到标准输出(屏幕).

So, when you're redirecting the output of echo to /dev/stdout, it is sent to the standard output (the screen) directly.

这篇关于stdout和/dev/stdout之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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