Talk:Check input device is a terminal: Difference between revisions

m
moved Talk:Detect input coming from terminal to Talk:Check input device is a terminal: We are primarily checking device type.
m (Terminal control)
m (moved Talk:Detect input coming from terminal to Talk:Check input device is a terminal: We are primarily checking device type.)
 
(One intermediate revision by the same user not shown)
Line 3:
 
: Or ''"Determine input from terminal"''? --[[User:Paddy3118|Paddy3118]] 22:48, 12 February 2013 (UTC)
 
==Interactive or not?==
 
Actually, it might be better to know whether the program is to operate interactively or not. I think this is probably what we need to know from an application point of view. To be interactive, we need to know that both the input and device and the output device is a terminal. If either the input device or output device are not terminals, then in most cases we probably do not want to be interactive.
Line 17 ⟶ 19:
 
[[User:Markhobley|Markhobley]] 15:58, 20 February 2013 (UTC)
 
Scrub the three flags crap. We can just return a value. Here is my proposed perl version:
 
<lang perl>sub checkinteractiverestriction {
my $restrictions = 0;
if (!-t STDIN) {
$restrictions |= 1; # No keyboard
}
if (!-t STDOUT) {
$restrictions |= 2; # No terminal
}
# Standard error redirection is not a restriction
# if (!-t STDERR) {
# $restrictions |= 4;
# }
return $restrictions;
}
 
if (checkinteractiverestriction() == 0) {
print "We are ok to operate interactively!";
}</lang>
 
[[User:Markhobley|Markhobley]] 10:37, 21 February 2013 (UTC)