doctor tim has asked for the wisdom of the Perl Monks concerning the following question:

I'm running as root user on a suse-linux box (bash). I have a csh script that, among other things, creates an executable file by invoking a FORTRAN compiler. I translated the csh script to perl. My perl script creates the 'executable' file, but permissions are r--r--r--. I added a line to the perl script
my $result = chmod 0755, $file;
$result is 1, but $file is still r--r--r--.
from the bash commandline chmod works fine:
chmod +x file
I've read a lot about unmask, but don't think I should have to mess with defaults. root owns $file and the perl script (and everything else).
Any suggestions? Thanks.
  • Comment on perl script cannot chmod but shell script does

Replies are listed 'Best First'.
Re: perl script cannot chmod but shell script does
by dave_the_m (Monsignor) on Jan 10, 2005 at 16:00 UTC
    umask shouldn't affect chmod. It's more likely that you're passing the wrong filename or you're in the wrong directory, or something like that. Try running the script using strace to see what args the actual chmod() system call is being invoked with.

    Dave.

Re: perl script cannot chmod but shell script does
by r34d0nl1 (Pilgrim) on Jan 10, 2005 at 16:22 UTC
    send us the source code surrounding this, so we would be clearer to us to try to check it.
    Anyway you also could use (to test, for example) the system function to check if it works; like in
    system("chmod a+rw /EntirePath/myFileName")

    good luck
Re: perl script cannot chmod but shell script does
by Fletch (Bishop) on Jan 10, 2005 at 18:29 UTC

    Append . . . or die qq{Can't chmod "$file": $!\n}; and see if you're getting an error back from chmod that you're missing right now.