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

Hello Monks,
I have this situation:
I have installed cwRsync (a Windows port of Rsync: http://www.itefix.no/i2/node/10650 ) on a Windows machine and I'm trying to use Perl to do a lot of stuff.
Finally I ask Perl to invoke my rsync command.

On a DOS console enviroment all runs as well.

But if I insert my Perl program in Windows Scheduling Tasks function, nothing works anymore.
I have already done a little debugging, and I have tried to isolate my problem.
So If I tried to run my Perl program in my DOS console. It contains this code:
system "rsync --version";
All works fine.
I have:
rsync version 3.0.7 protocol version 30 Copyright (C) 1996-2009 by Andrew Tridgell, Wayne Davison, and others. Web site: http://rsync.samba.org/ Capabilities: 64-bit files, 64-bit inums, 32-bit timestamps, 64-bit long ints, socketpairs, hardlinks, symlinks, IPv6, batchfiles, inplace, append, ACLs, no xattrs, iconv, symtimes rsync comes with ABSOLUTELY NO WARRANTY. This is free software, and y +ou are welcome to redistribute it under certain conditions. See the GNU General Public Licence for details.
That sounds good
But If I try to insert my Perl program in Windows Scheduled Tasks, I have this error:
2 [main] rsync 4008 C:\Programmi\cwRsync\bin\rsync.exe: *** fata +l error - couldn't initialize fd 0 for /dev/console
And this is pretty strange:
It seems rsync is not able to have the console from parent process (that is the Perl program)...
I have also tried to set up Environement variables, but without any gains:
$ENV{'CWRSYNCHOME'}='C:\Programmi\cwRsync'; $ENV{'CYGWIN'}='nontsec'; $ENV{'HOME'}='C:\Documents and Settings\saintex'; $ENV{'CWOLDPATH'}=$ENV{"PATH"}; $ENV{'PATH'}='C:\Programmi\cwRsync\bin;' . $ENV{'PATH'};
Moreover the same rsync command, in DOS batch style, works fine also if I call it from Scheduled Tasks:
@ECHO OFF SETLOCAL SET CWRSYNCHOME=C:\Programmi\cwRsync SET CYGWIN=nontsec SET HOME=C:\Documents and Settings\wolf SET CWOLDPATH=%PATH% SET PATH=%CWRSYNCHOME%\BIN;%PATH% rsync -av --delete '/cygdrive/c/Documents and Settings/saintex/Desktop +/to save' '/cygdrive/c/Documents and Settings/saintex/Desktop/myTest'
The rsync command is just a little part of my Perl program, so I can't translate all the stuff in DOS style (and I don't like to do it).
Any ideas?
Suggestions are welcome
Thank you!

Replies are listed 'Best First'.
Re: On win32 a scheduling task program doesn't work
by furry_marmot (Pilgrim) on Jun 18, 2010 at 18:52 UTC

    Showing the batch file is fine, but it won't help us with the Perl code. Let's see what you're doing.

      I will try a better explanation:

      The Perl code is simply this one:
      system "rsync --version";

      It is locate in a file:
      backup.pl

      From MS DOS prompt (I mean: perl -w backup.pl),
      It works fine and shows rsync version.

      The same code in the same file had that error:

      (2 main rsync 4008 C:\Programmi\cwRsync\bin\rsync.exe: *** fata +l error - couldn't initialize fd 0 for /dev/console)

      if I try to run the same backup.pl file from Windows Scheduled Task.
      That's strange.

        Chances are thta this is a "permissions problem". Ie. You have set the task up to run when there is no user logged on, but failed to supply the appropriate user-id / password. .

        But, it could also be a lack of a console, try system "cmd /c rsync --version";

        That's strange.

        That rsync wants a console, that scheduled tasks are run in the background, or that rsync can't find a non-existent console? The first isn't particularly strange, and the second and third sure aren't.

        Can rsync be told to work despite having no console? Does the scheduler give an option to run a task "interactively"?

        Okay. First, I assume you are using Win XP or Vista, right? The "MS DOS prompt" has been a command shell for quite a while. But anyway, does your code change to the correct directory? The scheduled copy might be starting in a default directory (like your user folder), and thus be in the wrong place.

        I don't think this is Perl problem, since you've demonstrated it works. I suspect it's either a permission problem, or it's starting in the wrong directory. Try checking the current directory from the script that's being run from the Windows Task Scheduler. Also try adding some lines to create or delete files, along with the result.

        --marmot
Re: On win32 a scheduling task program doesn't work
by afoken (Chancellor) on Jun 19, 2010 at 04:20 UTC

    Raw guess: Redirect STDIN of rsync to the NULL device, i.e.:

    rsync -av --delete '/from/somewhere' '/to/somewhere' < nul

    (DOS style)

    - or -

    rsync -av --delete '/from/somewhere' '/to/somewhere' < /dev/null

    (when cygwin provides /dev/null)

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
      With this syntax:
      rsync -av --delete '/from/somewhere' '/to/somewhere' < nul
      But Why?


      It is useful to know, that I do a redirect of both STDOUT and STDERR on a lo file.
      But I don't thing that is related to STDIN:
      $| = 1; # no output buffer open LOG, ">", LOG_FILE # LOG_FILE settings are in toConfig.pm or warn "Can't create LOG FILE: $!"; close LOG; open STDERR, ">>",LOG_FILE or warn "Can't redirect STDERR: $!"; open STDOUT, ">>",LOG_FILE or warn "Can't redirect STDOUT: $!";
      UPDATE
      It seems that all works fine, also without STDIN redirect, if I try to call my Perl program from Windows Scheduled Tasks, with that syntax:

      cmd /c "C:\Documents and Settings\saintex\Desktop\saintex-backup\backup.pl" -m alternative

      This way is also important to send options to perl file (without 'cmd /c' no options are passed to Perl program).

      Thank you all!
Re: On win32 a scheduling task program doesn't work
by Anonymous Monk on Jun 18, 2010 at 22:38 UTC
    Try scheduling the command without perl involved, it would likely fail the same way -- you should ask on cygwin forums