test for (non-)interactive program run 
Author Message
 test for (non-)interactive program run

Hi

Does anyone know how to check whether my program has been started from
an interactive shell or non-interactively by the cron-daemon? In the
interactive mode I want to have warning messages printed on the screen
and in the non-interactive case I want to write them to a specific file.

Thanks for your help.
Michael



Sat, 16 Jul 2005 18:24:03 GMT  
 test for (non-)interactive program run

Quote:

> Hi

> Does anyone know how to check whether my program has been started from
> an interactive shell or non-interactively by the cron-daemon? In the
> interactive mode I want to have warning messages printed on the screen
> and in the non-interactive case I want to write them to a specific file.

isatty(). But I think it's better to redirect the output from
cron to /dev/null. just append  >  /dev/null 2>&1  in crontab.

--
espen



Sat, 16 Jul 2005 18:28:00 GMT  
 test for (non-)interactive program run
Espen Myrland schrieb:
Quote:

>>Hi

>>Does anyone know how to check whether my program has been started from
>>an interactive shell or non-interactively by the cron-daemon? In the
>>interactive mode I want to have warning messages printed on the screen
>>and in the non-interactive case I want to write them to a specific file.

> isatty().

which module belongs it to?

Quote:
> But I think it's better to redirect the output from
> cron to /dev/null. just append  >  /dev/null 2>&1  in crontab.

I do so... with the normal output. But I want to keep error and warning
messages to see where problems may occur...

Best regards
Michael



Sat, 16 Jul 2005 19:23:38 GMT  
 test for (non-)interactive program run

Quote:

> Does anyone know how to check whether my program has been started from
> an interactive shell or non-interactively

   perldoc -f -t

--
    Tad McClellan                          SGML consulting

    Fort Worth, Texas



Sat, 16 Jul 2005 19:43:55 GMT  
 test for (non-)interactive program run

Quote:
> Espen Myrland schrieb:

> >>Hi

> >>Does anyone know how to check whether my program has been started from
> >>an interactive shell or non-interactively by the cron-daemon? In the
> >>interactive mode I want to have warning messages printed on the screen
> >>and in the non-interactive case I want to write them to a specific file.

> > isatty().
> which module belongs it to?

POSIX.  But you don't need it, "-t STDIN" will serve the same purpose,
that is, make a guess if your program is run interactively.

Quote:
> > But I think it's better to redirect the output from
> > cron to /dev/null. just append  >  /dev/null 2>&1  in crontab.

> I do so... with the normal output. But I want to keep error and warning
> messages to see where problems may occur...

I'd still prefer to make the behavior explicit in the call.  The
standard method is to have interactive output on STDOUT and errors
on STDERR.  Then only redirect STDOUT to /dev/null.  If anything
appears on STDERR, cron mails it to you.  That's even better than
having to watch a file.

If you must use a file, make it a parameter of your program (with or
without one of the GetOpt:: modules), and make the default behavior
the one you have now.  Then give it an output file in crontab.

Both ways are better than guessing if you run under cron.

Anno



Sat, 16 Jul 2005 21:24:56 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Running a non CGI program through a weblink

2. non-interactive ftp from perl

3. capture of data from a modem from a non-interactive process

4. Perl5a8 for NeXTs (Was: Non interactive Configure)

5. WANTED: non-interactive FTP perl script ?

6. Non-interactive ftp

7. non-interactive telnet session

8. Urgent: non-interactive password change...

9. non-interactive passwd script

10. Create non-interactive Perl/Tk application?

11. need a web server program to run/test cgi scripts in perl on a PC --Windows95

12. Testing for non-numerics in a scalar

 

 
Powered by phpBB® Forum Software