in reply to Re: CD and EXE
in thread CD and EXE

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";)

Replies are listed 'Best First'.
Re: Re: Re: CD and EXE
by Rich36 (Chaplain) on May 29, 2002 at 16:37 UTC

    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
Re: Re: Re: CD and EXE
by cjf (Parson) on May 29, 2002 at 16:33 UTC

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