sh 在shell中重定向

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 在shell中重定向相关的知识,希望对你有一定的参考价值。

#include <stdio.h>
int main()
{
  int a;
  int b;
  printf("type the first value...\n");
  scanf("%d", &a);
  printf("type the second value...\n");
  scanf("%d", &b);
  if(0 == b) {
    fprintf(stderr, "the second value can't be zero!\n");
    return 1;
  }
  printf("%d / %d = %d\n", a, b, a/b);
  return 0;
}
# output
# ./main.out [1]>> output.txt     append
# ./main.out [1]> output.txt      overwite
# input
# ./main.out < input.txt
# error
# ./main.out 2> error.txt
gcc redirect.c -o main.out
./main.out >>output.txt
cat output.txt
#type the first value...
#type the second value...
#2 / 1 = 2
./main.out >output.txt
cat input.txt
#2
#0
./main.out >output.txt <input.txt 2>error.txt
cat output.txt
#type the first value...
#type the second value...
cat error.txt
#the second value can't be zero!

以上是关于sh 在shell中重定向的主要内容,如果未能解决你的问题,请参考以下文章

在 Laravel 中重定向域名

使用参数在 blazor 中重定向

不要在 htaccess 中重定向子域

在 JSP 中重定向页面?

如何在NGINX中重定向一个网址

在win32中重定向标准输出不会重定向标准输出