2

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 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the quick reply! I will test it on Sunday and give you a Feedback :-)!
"... you would need to write a Bash script ..." that's not entirely true. Please see my answer for why.
2

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.

1 Comment

Thanks for your contribution, unfortunately i cannot flag both as solutions, as both work for me, you got my upvote :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.