in reply to Re: Re: main script invoked twice
in thread main script invoked twice

Read etcshadow's reply again. And try his suggestion. If it works, then the child's pid is irrelevant; you have a buffering problem. When running under cron, you'll be sending the output to a pipe, which may buffer more than sending it to a tty.

If setting $|=1 fixes the problem but you don't want to disable buffering, use { local $| = 1 } (including the curlies) to force a flush at the appropriate point -- probably just before the fork. ($|=1;$|=0 would do the same thing but wouldn't restore the buffering status, which is an unfriendly thing to do, especially if you're mixing in anyone else's code.)