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 |