Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

chmod does not work on windows/cygwin

Status
Not open for further replies.

whn

Programmer
Oct 14, 2007
265
US
Hi, Experts,

Here is a piece of my code:

Code:
my $ret = `ls -l $pkg`;
chomp($ret);
print "1. \$ret = $ret\n";
my $mode = 0755;
my $cnt = chmod $mode, $pkg;
$ret = `ls -l $pkg`;
chomp($ret);
print "\$cnt = $cnt\n";
print "2. \$ret = $ret\n";

The output:
Code:
1. $ret = -rw-rw-rw- 1 Administrator None 22824288 Jun  6 04:21 C:/tmp/myfile.exe
$cnt = 1
2. $ret = -rw-rw-rw- 1 Administrator None 22824288 Jun  6 04:21 C:/tmp/myfile.exe

I have tried all examples listed at this page:
Code:
# examples:
    $cnt = chmod 0755, 'foo', 'bar';
    chmod 0755, @executables;
    $mode = '0644'; chmod $mode, 'foo';      # !!! sets mode to
                                             # --w----r-T
    $mode = '0644'; chmod oct($mode), 'foo'; # this is better
    $mode = 0644;   chmod $mode, 'foo';      # this is best

None of above work. What am I missing here?

Many thanks.
 
What you are missing is that Windows does not support chmod.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Kevin, Windows/cygwin does support chmod and all unix cmds. I can run unix cmd 'chmod 755 filename' at cygwin prompt. I can run my perl codes on this host tool. But why perl built-in chmod would not work?

Thanks.
 
Windows does not support chmod, that is the problem. cygwin might perform some magic that enables a chmod command to work when run through cygwin but you can't use perls chmod() function on Windows anymore than you can use flock() or some or all of the get*() functions. Ask on if you need a second opinion.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Thank you, Kevin.

So, I guess I have to use `chmod 755 filename` then. Sigh.
 
So, I guess I have to use `chmod 755 filename` then. Sigh.
NO!

Windows does NOT support *nix file attribute settings.

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
To 1DMF,

It works when cygwin is installed.

Thanks.
 
What makes you beleive there is a module / plugin which changes the fundemental workings of a microsoft NTFS file system into a unix one?

Permissions are controlled in a completely different manner especially if it sits on a domain controller.

cygwin is a DLL which must perform 'translation' functions a bit like converting a 'chmod' command into an 'attrib' command.

But if you feel it serves your purpose, I wish you luck.



"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
I don't know the answer. All I know is my code works now.

BTW, how would you change file mode in your perl code running on windows?

There must be a way, right?
 
Dunno, I have a folder structure where some are public and some are not, any files I want to keep away from joe blogs I use the private folder.

If I want people to only be able to read files in a folder I again will have a folder where I store these and set permissions to read-only.

I guess if I really had to change a file attribute I might shell and run the dos command, or I'd have to use some module such as Win32::OLE



"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
My tool needs to extract an supposely executable from a zip file. however, this 'executable' often ends up 644 instead of 755. Therefore, my code had better change its mode before executing it.

It is easy on unix. But it seems so hard on windows/cygwin. I remember it was just as easy on windows/mks before.
 
My tool needs to extract an supposely executable from a zip file. however, this 'executable' often ends up 644 instead of 755. Therefore, my code had better change its mode before executing it.

In windows IIS the file attribute does not give permissions for executable status of a file. You have to set if executables can run via the IIS Manager for the specific domain.

Well that's how I do it.

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
The zip file is put on this windows host via ftp by a cron job. So IIS is not involved. But again, at least `chmod ...` works for me on windows/cygwin. I guess I can live with that.

Thanks you all for your help.
 
cygwin is a totally different environment so it does add Unix/Linux type commands to an otherwise Windows operating system environment, but only when run in the cygwin environment. So yes, chmod works in cygwin, but not in Windows.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
The zip file is put on this windows host via ftp by a cron job. So IIS is not involved.
sorry I thought you were serving the .zip file via the web in a windows environment.

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top