将文件重定向或通过管道传输到标准输出
如何重定向一个小(<20k)文件以通过管道传输到另一个程序,以便它永远不会写入光盘。
您可以使用 cfront 和 gcc 作为示例。只要您将通常输出文件的内容重定向到通常接受文件的内容,任何示例都可以。
您可以使用任何脚本或 shell,但我更喜欢看到 bash 或 perl。
How do u redirect a small(<20k) file to be piped to another program, so that it is never written to disc.
You could use cfront and gcc as an example. Any example will do as long as you are redirecting something that normally outputs a file to something that usually accepts a file.
You could could use any script or shell, but I would prefer to see bash or perl.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
有趣的!我尝试了这个:
几乎是一个管道...一个命名管道:p
另一方面,如果您有兴趣在标准输出上打印它(无需管道):
interesting! I tried this:
almost a pipe ... a named pipe :p
On the other hand if all you are interested in print it on stdout (without having to pipe):
如果一个程序期望从文件中读取它的输入,那么这几乎就是您必须要做的。为了避免接触文件系统,您使用的所有程序都必须了解如何从 stdin 读取和写入 stdout(或其他非文件系统的设备)。
Unix 世界中的许多程序都能够像读取文件一样轻松地读取和写入 std{in,out}。一个很好的例子是 gnu tar 和 gzip。 tar 可以写入标准输出并将输出直接通过管道传送到 gzip:
tar cf-foo/| gzip -c > > foo.tgz
但这需要 tar 和 gzip 都能够读取/写入 stdin/stdout 以及常规文件。
如何在自己的程序中实现这一点取决于所涉及的语言,但在大多数情况下处理 stdout & stderr 与任何其他文件几乎相同。您的命令行参数应该允许用户选择此选项。
If a program is expecting to read it's input from a file then that's pretty much what you're going to have to do. To avoid touching the file system, all the programs you are using have to understand how to read from stdin and write to stdout (or some other device that's not a file system).
Many programs in the unix universe are capable of reading from and writing to std{in,out} just as easily as they are to a file. A good example is gnu tar and gzip. It's possible for tar to write to stdout and to pipe that output directly into gzip:
tar cf - foo/ | gzip -c > foo.tgz
but that requires both tar and gzip to be able to read/write to stdin/stdout as well as regular files.
How you achieve this in your own program depends on the language involved but in most cases handling stdout & stderr is pretty much the same as any other file. Your command line arguments should allow the user to choose this as an option.
如果程序A要运行程序B,可以使用
open
< /a> 函数在 A 和 B 的STDIN
之间创建匿名管道:program A.pl:
program B:
If program A is going to run program B, you can use the
open
function to create an anonymous pipe between A and B'sSTDIN
:program A.pl:
program B: