M
Martin Kissner
hello together,
I have a very strange problem with the system() command and/or the
backtick operator.
I can not provide a small demonstration script because when I wrote the
script (see below) the very same commands worked properly.
The main script is (among other things) supposed to download files from
a ftp server and then change the file permissions of the local files to
those on the server.
I use Net::FTP for this script.
The download part works okay, but the permissions of the local files are
only changed, if the octal value is greater or equal 400.
Here is the sub which shows this strange behavior.
--- snip ---
[...]
use warnings;
use strict;
[...]
sub copy_file {
my $file = shift; # remote filepath
my $action = shift; # "0" => put; "1" => get
if ($action) {
my $lfile = strip_slash($file);
$ftp->get($file,$lfile);
my $octal = get_permissions($file,"r");
# print "`chmod $octal $lfile`\n";
# `chmod $octal $lfile`;
system("chmod $octal $lfile 2>/dev/null") == 0
or warn "\"chmod $octal $lfile\" failed!\n";
} else {
$ftp->put($lfile,$file);
}
set_l2rmtime($file);
}
--- snap ---
If I copy/paste the output from the print statement or from warn"..." to
the terminal, the chmod works.
As I said above if $octal is 400 or greater it also works!!!
If $octal is 377 or less I get:
"chmod 377 testdir/testfile.txt" failed!
If I omit the '2>/dev/null' part I get
"chmod: testdir/testlfile.txt: No such file or directory"
but only if $octal is less than 400.
I also tried working with absolute paths with the same results.
Then I wrote this little script for testing and demonstration:
--- snip ---
#!/usr/bin/perl
use warnings;
use strict;
my $octal = $ARGV[0];
# print "`chmod $octal testdir/testfile.txt`\n";
# `chmod $octal $lfile`;
system("chmod $octal testdir/testfile.txt") or warn "\"chmod $mode
testfile.txt\" failed!\n";
--- snap ---
I have testes this successfully for $octal from 0 to 777 (with backticks
and with system("...")).
At this point I have tried everything I could imagine.
Any help will be highly appreciated.
Best regards
Martin
I have a very strange problem with the system() command and/or the
backtick operator.
I can not provide a small demonstration script because when I wrote the
script (see below) the very same commands worked properly.
The main script is (among other things) supposed to download files from
a ftp server and then change the file permissions of the local files to
those on the server.
I use Net::FTP for this script.
The download part works okay, but the permissions of the local files are
only changed, if the octal value is greater or equal 400.
Here is the sub which shows this strange behavior.
--- snip ---
[...]
use warnings;
use strict;
[...]
sub copy_file {
my $file = shift; # remote filepath
my $action = shift; # "0" => put; "1" => get
if ($action) {
my $lfile = strip_slash($file);
$ftp->get($file,$lfile);
my $octal = get_permissions($file,"r");
# print "`chmod $octal $lfile`\n";
# `chmod $octal $lfile`;
system("chmod $octal $lfile 2>/dev/null") == 0
or warn "\"chmod $octal $lfile\" failed!\n";
} else {
$ftp->put($lfile,$file);
}
set_l2rmtime($file);
}
--- snap ---
If I copy/paste the output from the print statement or from warn"..." to
the terminal, the chmod works.
As I said above if $octal is 400 or greater it also works!!!
If $octal is 377 or less I get:
"chmod 377 testdir/testfile.txt" failed!
If I omit the '2>/dev/null' part I get
"chmod: testdir/testlfile.txt: No such file or directory"
but only if $octal is less than 400.
I also tried working with absolute paths with the same results.
Then I wrote this little script for testing and demonstration:
--- snip ---
#!/usr/bin/perl
use warnings;
use strict;
my $octal = $ARGV[0];
# print "`chmod $octal testdir/testfile.txt`\n";
# `chmod $octal $lfile`;
system("chmod $octal testdir/testfile.txt") or warn "\"chmod $mode
testfile.txt\" failed!\n";
--- snap ---
I have testes this successfully for $octal from 0 to 777 (with backticks
and with system("...")).
At this point I have tried everything I could imagine.
Any help will be highly appreciated.
Best regards
Martin