http://www.perlmonks.org?node_id=344393

crabbdean has asked for the wisdom of the Perl Monks concerning the following question:

I've created a program that accepts commandline paramaters at runtime. One of these is to create a log file, another is to set verbose mode so that output is put to STDOUT instead of the logfile. Another flag "--help" outputs help to the STDOUT. 'print' statements are to the filehandle LOGFILE that I duplicate to STDOUT if the verbose flag is set. (see code below).

As a perl .pl this all works fine.

I then compile this script into a PAR archive executable using the --gui option so that there is no console when running the executable (I need it like this because I don't want a console). Now I know that with the --gui option it doesn't create a console, but I thought when running it from a command line you'd still get the output to STDOUT (and I do need this STDOUT functionality)

So I'm guessing two possible causes:
1. PAR --gui suppresses STDOUT completely.
2. OR, I've opened the duplicate filehandle to STDOUT incorrectly (although it does work as a .pl and when simply PAR'ed (without --gui) but not when compiled as PAR --gui

If No. 1 is true, then I need to find out how to suppress the console from a perl EXE and still get STDOUT if run from a command line. Anybody know how to do this or what's going on?
if ($createlog || $logfile) { $verbose = 1; ## if createlog specified but no logfile name given then ## create default logfile name if (!$logfile) { $logfile = "./logs/ZIPsync_$day.log"; ## Make Logs folder eval { mkpath("./logs") }; if (-e $logfile && (time - (stat $logfile)->mtime) > 86400) { + unlink $logfile; open (LOGFILE, ">$logfile") or dying($!); } else { open (LOGFILE, ">>$logfile") or dying($!); } } else { open (LOGFILE, ">$logfile") or dying($!); } } ## output to STDOUT if $verbose mode seleted but no output log if ($verbose && !$createlog && !$logfile) { open (LOGFILE, ">&1") or dying($!); }

Dean
The Funkster of Mirth
Programming these days takes more than a lone avenger with a compiler. - sam
RFC1149: A Standard for the Transmission of IP Datagrams on Avian Carriers