Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Running Perl with Cygwin

by cocl04 (Sexton)
on Jun 23, 2009 at 20:25 UTC ( [id://774163]=perlquestion: print w/replies, xml ) Need Help??

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

All, I resently installed cygwin on my windows pc. Prior to using cygwin, I used dos to run all of my bat files, perl, sql, etc... I can run all of my bat files for perl and sql in dos and / or cygwin. However, when I attempt to run the perl script directly at the command line in cygwin, I get the below error.

Can't locate DBI.pm in @INC

Initially, I tried the "use lib" module to point to the modules directory. It did not work.

It is very strange, because the perl script will run in cygwin as a bat file (i.e. ./test.bat) in the below format.

c:\test_error\test.pl > PERL_ERROR.log 2>&1

However, it will not run at the command line. I have tried some of the following options:

perl -w test.pl or ./test.pl

And I still get the error. Does anyone have any suggestion? How would perl run at all if the modules where not installed correctly? What is different about cygwin? Is there some kind of global view when running a bat file that cygwin does not see at the command line?

Replies are listed 'Best First'.
Re: Running Perl with Cygwin
by ikegami (Patriarch) on Jun 23, 2009 at 20:37 UTC

    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.

      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

      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
Re: Running Perl with Cygwin
by CountZero (Bishop) on Jun 23, 2009 at 20:32 UTC
    I don't have cygwin installed myself, but <guessing_mode>maybe cygwin comes with its own Perl and modules </guessing_mode>?

    Update: But that doesn't explain why it would run from inside a .bat file.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://774163]
Approved by moritz
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2024-04-20 01:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found