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

I'm creating a Perl script that will compile java code and create a jar file from it. The script resides in

c:\Files\

My souce resides in:

c:\Files\splatt\src\

The hitch is that the class files are compiled to a different directory than the one the script resides in. For example:

$MakeGistMain = "javac $java_opt $class_dir splatt\\src\\.java"; system ($MakeGistMain);

compiles to $class_dir. When it's time to create the jar I need to chage to the directory that contains the class files and jar them up:

$cd_class_dir = "cd $class_dir"; system($cd_class_dir); system("jar -cvf splatt.jar splatt");

What this does is create a jar file containing the .java files, not the .class files, suggesting that the cd isn't actually executed properly. Is there something I'm not doing?

Replies are listed 'Best First'.
Re: How do I change directories from within a script?
by Hot Pastrami (Monk) on Dec 14, 2000 at 01:51 UTC
    Use chdir() to change directories

    Alan "Hot Pastrami" Bellows
      Ah...! Thanks! Learning a new language can be terribly embarassing at times! :)

      There's nothing more dangerous than a resourceful idiot. --- Dilbert

        The reason that system("cd some_dir") doesn't work is because the system call is spawning a new process (in this case a shell), so any changes made to that shell's environment (such as changing the current working directory) are lost when the sub-process exits. You end up creating a child process and sending it to a new directory, where it expectedly dies/exits of natural causes and returns control back to you. You didn't move anywhere.