in reply to CD and EXE

chdir

Replies are listed 'Best First'.
Re: Re: CD and EXE
by Anonymous Monk on May 29, 2002 at 16:20 UTC
    Sorry, I should have been more clear. I want to cd to a differnt directory and start a command from there all in one line (ie system "cd /foo $bar.exe";)

      On Unix, you can separate the two commands by a semi-colon system("cd /foo; $bar.exe");. It would probably be better to use chdir or the full path as suggested since using the semi-colon in that command doesn't take into account what could happen if the "cd" fails (nor is it cross-platform compatible if the need arises). I would suggest using something like:

      #!/usr/bin/perl use strict; use warnings; use Cwd qw/chdir/; # comes in standard Perl distro my $bar = "someprogramname"; chdir("/foo") or die "Couldn't cd to /foo!\n"; system("$bar\.exe") or die "Couldn't execute $bar\.exe!\n";

      Rich36

      Using the full path like so: qx('/usr/bin/perl'); should do the trick.