Re: Permission denied writing to Windows 10
by Corion (Patriarch) on Sep 14, 2016 at 15:28 UTC
|
What is your current directory? Most likely, you are simply not allowed to write to whatever directory is your current directory.
You can find the current directory with the following Perl code:
use Cwd;
print "Current directory is: ", getcwd;
open FILE, ...
| [reply] [d/l] |
|
| [reply] |
|
What is the full path? WinDoze got picky about writing to "\Program Files\whatever...." some time ago. Running as Admin doesn't always override that.
Writing to C:\Public, on the other hand, is unlikely to give you problems, but whatever the issue may be, you'll be well served to create a new directory, on another (local) drive if that's available in which to put your new work. Commingling your Perl install with homework, experiments, learning-challenges and other scripts will be a hassle a few weeks or months from now.
Just BTW, as this has already been partially addressed by way of correction, but I don't know how the open shown in your OP could work, period, given the missing close-quote, comma operator, space, open-quote sequence. Of course, sometimes I miss the memo... and I did not test your version because I expected a syntax error.
Update: Please don't read the preceding paragraph. Pretty Please? See Rev. Canon AnomalousMonk's reply below. Watch ww flush with embarrasment! Mea Culpa.
| [reply] [d/l] |
|
|
|
| [reply] [d/l] |
|
|
|
Re: Permission denied writing to Windows 10
by stevieb (Canon) on Sep 14, 2016 at 18:31 UTC
|
I just did a test on one of my win2k8r2 boxes, and I can reproduce the permission denied error by setting the Read Only flag on the hello.txt file before running the open on it. Could this possibly be your case?
# after setting the RO bit
c:\>perl -E "open FILE, '> hello.txt' or die $!"
Permission denied at -e line 1.
Note that you should be using 3-arg open, and lexical, not bareword file handles:
open my $fh, '>', 'hello.txt' or die $!;
| [reply] [d/l] [select] |
|
Thanks for correcting my use of open. I have changed to use the 3-arg open with lexical handles.
Hello.txt as a file does not exist before running the script. The idea is that the script creates file. So if it doesn't yet exist, then it can't be RO, right? Is it possible that files are getting created as RO for some reason?
| [reply] |
Re: Permission denied writing to Windows 10
by BrowserUk (Patriarch) on Sep 14, 2016 at 15:47 UTC
|
How are you running the script? Ie. from the Explorer, or a command line, or ...
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] |
|
| [reply] |
Re: Permission denied writing to Windows 10
by Anonymous Monk on Sep 14, 2016 at 19:42 UTC
|
| [reply] |
|
Error
13 Permission denied
5 Access is denied
ERROR_INVALID_DATA
EVENT_SYSTEM_CONTEXTHELPEND
EMR_SETBRUSHORGEX
EACCES
EMARCH_ENC_I17_IMM5C_INST_WORD_POS_X
#
status($?) 0
subexit($? >>8) 0
signal($? & 127) 0
coredump($? & 128) 0
at test.pl line 33.
| [reply] [d/l] |
|
| [reply] [d/l] [select] |
Re: Permission denied writing to Windows 10
by Pickwick (Beadle) on Sep 15, 2016 at 13:02 UTC
|
Thoughts?
Process Monitor of the Sysinternals Suite will exactly tell you which file you tried to create/access and why it failed. Just search for "ACCESS DENIED" in the monitoring results and you will find your path, which is most likely not what you think it is.
https://technet.microsoft.com/de-de/sysinternals/processmonitor.aspx
https://technet.microsoft.com/de-de/sysinternals/bb795533.aspx
| [reply] |
|
ou will find your path, which is most likely not what you think it is.
That doesn't really gell with what we've discovered so far. If he can create the file from the command line using shell redirection; there should be no reason that perl running at that exact same command prompt cannot also create/write to the file.
That places the problem firmly in the realms of Perl -- most likely there's something weird about the installation -- rather than anything to do with the OS or permissions.
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] |
|
on such OS the path is always important:
# 64bit cmd.exe launched as Administrator (via right click runas)
C:\Windows\system32>echo wrote > "c:\Program Files\_ONE.txt"
C:\Windows\system32>type "c:\Program Files\_ONE.txt"
wrote
# Perl 32 bit
C:\Windows\system32>C:\path\strP5.22-32\perl\bin\perl.exe -e "system q
+q(echo WroteByPerl > $ARGV[0] ) or die $^E"
"c:\Pro
+gram Files\_TWO.txt"
File esauriti at -e line 1.
# the above error is in italian, as the OS, and means 'There are no mo
+re files.'
# Perl 64 bit
C:\Windows\system32>C:\path\straw64\perl\bin\perl.exe -e "system qq(ec
+ho WroteByPerl64bit > $ARGV[0] ) or die $^E"
"c:\Progra
+m Files\_TWO.txt"
Accesso negato at -e line 1.
# Access Denied
L*
There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
| [reply] [d/l] |
|
|
If he can create the file from the command line using shell redirection; there should be no reason that perl running at that exact same command prompt cannot also create/write to the file.
What you were doing was guessing, Process Monitor on the other hand would have told exactly what is happening by the interesting process where, with which args and results. In cases like those guessing is a waste of time if proper tools to tell one are already available.
| [reply] |
|