shell – 我们如何通过使用isatty函数来区分对程序的输入是定向
发布时间:2020-12-15 21:00:03 所属栏目:安全 来源:网络整理
导读:我在此链接上询问了有关Stack Overflow的类似问题: Why is it that we can redirect the input of ‘less’ command,but we can’t run less without any arguments? 这让我想到了这个: 我们如何区分我们程序的输入是针对的,还是仅仅是用户的输入? 谁能给
我在此链接上询问了有关Stack Overflow的类似问题:
Why is it that we can redirect the input of ‘less’ command,but we can’t run less without any arguments? 这让我想到了这个: 解决方法
isatty示例:
#include <unistd.h> #include <stdio.h> int main() { if( isatty(STDIN_FILENO) ) puts("Connected to a terminal"); else puts("Not connected to a terminal"); return 0; } 正在使用: $gcc isatty.c $./a.out Connected to a terminal $echo hello | ./a.out Not connected to a terminal 没有那么简单! (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |