在 shell脚本中调用一个C语言的可执行程序,如何将C程序中printf的字符保存成到文件中?

例如:C程序为

#include <stdio.h>
int main()
{
printf("hello world!");
return 1;
}
编译后的结果为 helloExe
如果用shell调用helloExe后,如何将helloExe中打印的"hello world!"字符保存成文件?

在shell调用时,重定向输出的信息:

./helloExe > test.txt

hello  world!就保存到文件test.txt中了。

温馨提示:答案为网友推荐,仅供参考
第1个回答  2014-03-13
shell 里面就直接重定向吧 比如你的程序是hello,那么就是hello > output.txt
第2个回答  2014-03-13

命令如下

./helloExe > savefile

第3个回答  推荐于2017-11-26
chmod u+x helloExe
./helloExe > file

本回答被提问者采纳
相似回答