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

I am looking to set up my Perl program to run automatically when my MS Windows is booted up. No problem there using Startup, but this program does not respond in the same way to input files. I am guessing that the problem either lies in the use of the system call to another Perl program or the use of Perl modules. Does anyone have experience of a problem like this? It is a bit of a pain to debug this because I can't easily capture the error message. The program works fine when I open up a DOS shell and run it from there.

Replies are listed 'Best First'.
Re: Startup Perl program
by Joost (Canon) on Aug 19, 2005 at 11:40 UTC
    Try this at the start of your program:
    BEGIN { open STDERR,">",'C:/perl-errors.txt' or die "Can't redirect errors: +$!"; }

    That will save all STDERR messages (like those from warn(), die() and compiler errors to the file.

    If the error log doesn't give you enough information to figure out the problem, please post the error and the relevant code. It's not easy debugging programs with only an informal description of the program and no error messages.

Re: Startup Perl program
by inman (Curate) on Aug 19, 2005 at 12:16 UTC
    No problem there using Startup

    Can you clarify what you mean by startup? When Windows boots, the services are started and then the commands in the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run, RunOnce and RunOnceEx registry keys are executed. When an individual user logs into Windows, a similar set of registry keys under HKEY_CURRENT_USER are executed. In addition to that, the login script (if configured) will be run. The contents of the Startup menu will also be executed.

    The nature of the problems that you may experience differ depending on which part of the process you are trying to use.

Re: Startup Perl program
by radiantmatrix (Parson) on Aug 19, 2005 at 15:54 UTC

    I have had similar problems with Perl scripts in the Startup folder. I think it might have to do with certain environment variables (like PATH) not being properly initialized, because the following worked for me. Caveat emptor: I haven't thoroughly diagnosed this; the fix below fixed it, and I didn't investigate any further, YMMV.

    @ECHO OFF REM -- this is a .CMD script named 'C:\sperl.cmd' to launch Perl at st +artup. set PERL_BIN=C:\Perl\bin\perl.exe echo == %1 >> C:\startup.log %PERL_BIN% -w %* 1>>C:\startup.log 2>&1

    This is called like:

    C:\sperl.cmd C:\path\to\script.pl and some args

    A file named C:\startup.log is appended to: I have a logon script that erases this file before the Startup folder is ever executed, so you'll have to address that issue as well.

    <-radiant.matrix->
    Larry Wall is Yoda: there is no try{} (ok, except in Perl6; way to ruin a joke, Larry! ;P)
    The Code that can be seen is not the true Code
    "In any sufficiently large group of people, most are idiots" - Kaa's Law
      I had an issue like this one time when running a scheduled task. It had something to do with the account in which it was running under because the script lived on a network share. Make sure "system" has correct rights and try the examples from above. If I remember right I had to have the script on C:\ then do some "net use" to map a drive. At one point I think we used the account that is always logged in at the console? hope that helps