At 06:20 PM 9/3/2002 +0100, Sandy Fleming wrote:
>It works bery nicely with these commands, but I can't get it to work with
>SET DEFAULT at all:
>
>open(OUT,"|\@sys\$input");
>print OUT "set default $x\n";
>close(OUT);
>
>Where the variable $x holds the directory path as a string. This gives no
>errors, it just doesn't change the directory default.
Yes it does. It changes it for the subprocess you create with the piped
open, but that doesn't affect the parent process. In this slightly fuller
version of your example, you can see that the current working directory is
changed in the subprocess but not in the parent:
$ type foo.pl
$x = 'sys$scratch';
open(OUT,"|\@sys\$input");
print OUT "set default $x\n";
print OUT "show default\n";
close(OUT);
system("show default");
$ perl foo.pl
DISK8:[BERRYC.SCRATCH]
DISK8:[BERRYC.TEST]
What exactly is your goal? Do you just need to change directories for the
duration of your Perl program? If so, chdir() should do the trick:
$ perl -e "chdir 'sys$scratch'; system('show default');"
DISK8:[BERRYC.SCRATCH]
$ show default
DISK8:[BERRYC.TEST]
You can see that the effects of chdir() do not persist after program exit.
In C you can change that by specifying an optional second argument to
chdir() (or calling from SUPERVISOR or EXECUTIVE mode) but I can't think
right off how to do that in Perl. Do you need that? I.e. should the change
persist after your Perl program exits?