Shell重定向VS明确的文件处理code [英] Shell redirection vs explicit file handling code

查看:308
本文介绍了Shell重定向VS明确的文件处理code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不是以英语为母语,所以请原谅这个问题的尴尬称号。我只是不知道如何短语变得更好。

我在FreeBSD的盒子,我有一点点的过滤工具,写在 C 它通过标准输入并通过标准输出输出处理列表。我调用它有点像这样:找到。型F | myfilter> /tmp/processed.txt

I am on a FreeBSD box and I have a little filter tool written in C which reads a list of data via stdin and outputs a processed list via stdout. I invoke it somewhat like this: find . -type f | myfilter > /tmp/processed.txt.

现在我想给我的过滤器一点点曝光和发布。公约说,工具应该允许这样的事情:找到。型F | myfilter -f - -o /tmp/processed.text

Now I want to give my filter a little bit more exposure and publish it. Convention says that tools should allow something like this: find . -type f | myfilter -f - -o /tmp/processed.text

这将迫使我写code,根本没有必要的,因为壳可以做的工作,所以我倾向于离开它。

This would force me to write code that simply is not needed since the shell can do the job, therefore I tend to leave it out.

我的问题是:是否我错过了一些参数(但其他约定)为什么文件的阅读和写作应该在我的$ C $完成c。将不授予Shell重定向

My question is: Do I miss some argument (other but convention) why the reading and writing of files should be done in my code an not delegated to shell redirection?

推荐答案

有绝对没有错。您的过滤器将有类似的接口,比方说, C ++ FILT

There's absolutely nothing wrong with this. Your filter would have an interface similar to, say, c++filt.

如果你想自动选择输出文件根据输入文件名,或者如果你想特殊处理在单个命令处理多个文件,你可能会考虑的文件处理。

You might consider file handling if you wanted to automatically choose an output file based on the name of an input file or if you wanted to special handling for processing multiple files in a single command.

如果你不想做任何上述任一那么有什么错是一个简单的过滤器。任何人都可以提供一套简单的外壳包装提供了 CMD INFILE OUTFILE 语法,如果他们希望的。

If you don't want to do any either of these then there's nothing wrong with being a simple filter. Anyone can provide a set of simple shell wrappers to provide a cmd infile outfile syntax if they wish.

这篇关于Shell重定向VS明确的文件处理code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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