2
votes

i have the following issue:

I try to start a perl script from the windows scheduler through cygwin

Steps i do: Call process.bat file In the process.bat i call bash with the parameter for the perl script

Symptoms: If i call "perl scriptpath" directly from cygwin it works like a charm If i call the script from the windows cmd with bash it will not work.

Command: C:\cygwin\bin\bash.exe --login /cygdrive/c/scripts/testscript.pl It prints the following:

Line 3: use: command not found
Line 4: use: command not found
Can't find file Test

Script:

#!/usr/bin/perl

use strict;
use warnings;
print "Test";

Probably i'm making only a small mistake and cannot see it. It seems to interpret it with the windows cmd instead of the perl.

2

2 Answers

4
votes

The parameter passed to bash will be treated as a Bash script, not a Perl script. There is no reason to use Bash in this case - just invoke Perl directly:

C:\cygwin\bin\perl.exe /cygdrive/c/scripts/testscript.pl

If you really want to do it your way - calling a cmd script which calls a Bash script which calls a Perl script - then you would need to write a Bash script to invoke your Perl script:

#!/bin/sh
/cygdrive/c/scripts/testscript.pl

And pass that Bash script as the parameter when you invoke bash.

2
votes

You might like to use option -c to have bash execute a command, like this:

C:\cygwin\bin\bash.exe --login -c /cygdrive/c/scripts/testscript.pl 

From the bash's man-page:

-c string

If the -c option is present, then commands are read from string. If there are arguments after the string, they are assigned to the positional parameters, starting with $0.