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

Hi, I am running a perl script on windows2000 using cygwin utility. The perl script executes a java command thru the backtick operator. For this purpose it requires classpath variable.
The problem is that though the classpath has been set thru the Controlpanel, the cygwin utility didnot interpret windows type backslash (\) in the path correctly. Cygwin support told me to set the classpath in perl script instead.
Question is, if I set the classpath from perl script, will it override teh CLASSPATH var set through control panel ? How do I set the classpath variable in perl script ?(I am new to scripting with perl , using windows, so if this is a basic question, dont shoot !! Please bear with me). thanks.
  • Comment on CLASSPATH in perl on windows using cygwin

Replies are listed 'Best First'.
Re: CLASSPATH in perl on windows using cygwin
by xorl (Deacon) on Aug 26, 2004 at 18:41 UTC
    Just set the classpath when you execute the java command...
    #!/usr/bin/perl # perl stuff here `java -classpath /cygdrive/c/java/myclasspath myjavathingy.class` # more perl stuff here
    Also Cygwin in my experience usually doesn't change Windoz variables so you should be safe if you want to set the classpath variable when you open up Cygwin.
Re: CLASSPATH in perl on windows using cygwin
by Anonymous Monk on Aug 26, 2004 at 18:42 UTC
    Adding to this, I would like to know what is the best way to set the classpath from PERL script. Do I need to hardcode the path inside the script, or should it be read from a separate file and do something like:
    $ENV{CLASSPATH}=`cat file_with_classpath`;
    This further confuses me, since why not just do
    $CLASSPATH=`cat file_with_classpath`;
    since the java will be called as:java -classpath $CLASSPATH myprogram abc`;
    I am finding this really confusing. !! Please clarify.

      $CLASSPATH=`cat file_with_classpath`; is perfectly acceptable, and probably better in general than setting an environment var. I might have Perl open the file on its own to read the contents instead of calling cat, though. IO::All is nice for this:

      use IO::All; $CLASSPATH = io('file_with_classpath')->slurp;

      "There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.