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($!);
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.