in reply to Running Perl with Cygwin

because the perl script will run in cygwin as a bat file

Cygwin is a compatibility library. You can have cygwin builds of programs, but you can't run in cygwin. Do you mean in bash?

But bash can't process batch files, and I strongly doubt that anyone has made a cygwin build of a batch file interpreter, so that makes no sense.

So let's start over.

You're starting perl from two different shells. A cygwin build of bash (which you referred to as the command line), and the cmd Windows shell (which interpreted your batch file).

There's some difference between the two (PATH? PERL5LIB?), and the easiest way to find out what it is to run perl -V (that's an uppercase "V") from bash ("the command line") and from a batch file.

Could you please post those results and the output of the following command (run from a batch file):

perl -le"use DBI; print $INC{'DBI.pm'}"

I suspect you have two installations of Perl. One from before you installed Cygwin (which has DBI installed), and a cygwin build of Perl (which doesn't). Differences in the PATH of the two environments affect which installation is being used.

Replies are listed 'Best First'.
Re^2: Running Perl with Cygwin
by cocl04 (Sexton) on Jun 23, 2009 at 21:11 UTC

    I appreciate the question / clue. I was using two different perls. I added the below line to my perl script to use the same perl.exe:

    #!/cygdrive/c/Perl/bin/perl.exe

    Then I used the below line in cygwin to run it.

    ./test.pl

    That worked. Once we pointed the perl script to the correct interpreter the scripted processed.

    Thanks!!!!!

      cocl04:

      If changing the shebang to that made your script work, then I assume you're running a bash shell. But from the thread, I thought you wanted to run the cygwin version of perl. Unless you've got an unusual configuration, you're not running the cygwin version...

      ...roboticus
Re^2: Running Perl with Cygwin
by cocl04 (Sexton) on Jun 24, 2009 at 20:02 UTC

    Final Question: I can run the perl file from the cygwin build of bash only if I am in the correct directory by using the following:

    ./test.pl

    However, when I try to use the absolute path (i.e. /cygdrive/c/test_error/test.pl) in cygwin I get the below message:

    No such file or directory

    It appears that the interpreter (ActivePerl) does not like the directory format from cygwin. Is there a way for the bash shell to send the directory data to the interpreter in a format that it will except?

      If I were to guess as to what's happening, when cygwin tries to execute /cygdrive/c/test_error/test.pl, it notices the shebang line (#!/cygdrive/c/Perl/bin/perl.exe) and executes the following instead:
      /cygdrive/c/Perl/bin/perl.exe /cygdrive/c/test_error/test.pl

      Cygwin has no problem problem understanding /cygdrive/c/Perl/bin/perl.exe, but ActivePerl is not a cygwin application, so it can't open /cygdrive/c/test_error/test.pl.

      The simplest solution would be to use your cygwin build of Perl when launching scripts from a cygwin application (like bash).

      cocl04:

      You might want to read the cygpath documentation. It's a cygwin tool that converts between Unix and Windows style paths.

      ...roboticus
        Looks like for Cygwin Perl default installation it will not install Perl but use the existing Perl installation which I have i.e Strawberry Perl. To install Cygwin Perl, you must change Perl () Default" to change it to "Perl () Install"
        Check out this URL for pointers on how to use cygwin perl and AS perl together. http://www.cs.unc.edu/~jeffay/dirt/FAQ/cygwin-perl.html