Skip to content

cron atty::is(atty::Stream::Stdin)  #52

Open
@nbari

Description

I have a program that reads from stdin only when isatty returns false

let input_stdin = !atty::is(atty::Stream::Stdin); 

When running this from a cron it always returns true like if there were something in stdin but there is nothing.

use atty::Stream;

fn main() {
    if atty::is(Stream::Stdout) {
        println!("I'm a terminal");
     } else {
        println!("I'm not");
     }

     let input_stdin = !atty::is(atty::Stream::Stdin); // isatty returns false if there's something in stdin.
     if input_stdin {
         println!("stdin"); // how to prevent this to happen when calling it from a cron
     }

}

Any idea how to prevent this so that I could call my app from a cron job and distinguish when there is something in stdin and not?

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions