Re: open vs. sysopen
by oha (Friar) on Dec 26, 2003 at 17:04 UTC
|
no idea, i humbly suggest to try open with O_RDWR flag set instead of O_WRONLY. I also suggest you to write down you OS, and the kind of fs you ar using (mounted?).
more: do POSIX::open() works?
this may give more information to fix it. | [reply] [Watch: Dir/Any] |
|
Changing to O_RDWR doesn't help.
OS: Slackware 9.1 Linux 2.4.23
fs: /dev/hdd3 / ext2 rw 0 0
POSIX::open() works fine
Thanks!
-sheep
| [reply] [Watch: Dir/Any] |
|
Perhaps you can supply some additional code, or a small test case that
exhibits the behavior. The following two lines of code behave properly on
my Slackware Linux box (2.4.18), assuming proper permissions on directories
involved in the filepath.
open(DEST,'>',$ggg) or die $!;
sysopen(DEST, $ggg, O_WRONLY | O_TRUNC | O_CREAT) or die $!;
| [reply] [Watch: Dir/Any] [d/l] |
Re: open vs. sysopen
by melora (Scribe) on Dec 26, 2003 at 17:55 UTC
|
Okay, it was just a thought (kind of thing I'd goof up). I played with sysopen a little (not use-ing anything at all) and this worked okay (I shifted $file from the command line, and it was simply sheep.txt):
sysopen(FH, $file, O_WRONLY | O_TRUNC | O_CREAT);
print FH "Whooyah";
goshdammitforgot to use code brackets!
It did write Whooyah to the file, so it worked all right. So maybe the trouble is in the $file string you're giving it, after all.
| [reply] [Watch: Dir/Any] [d/l] |
|
I tried one or the other (commenting out one) not both at the same time.
The "$ggg" file, as well as "DEST" filehandle is used only in this bit.
| [reply] [Watch: Dir/Any] |
|
Okay, it was just a thought (kind of thing I'd goof up). I played with sysopen a little (not use-ing anything at all) and this worked okay (I shifted $file from the command line, and it was simply sheep.txt):
sysopen(FH, $file, O_WRONLY | O_TRUNC | O_CREAT);
print FH "Whooyah";
It did write Whooyah to the file, so it worked all right.
So maybe the trouble is in the $file string you're giving it, after all.
| [reply] [Watch: Dir/Any] |
Re: open vs. sysopen
by Aristotle (Chancellor) on Dec 26, 2003 at 22:35 UTC
|
I can't reproduce this on my fairly similar system.
Are we talking about the same values of $ggg here for all invocations?
Have you made sure the sysopen variant fails consistently? How many times did you try, under what circumstances? Was this the only thing you changed in your code and its environment (such as user ID etc) between test runs?
I know these questions are fairly basic, and I didn't initially reply because I have no idea why it would fail. I was hoping that someone else would be able to pinpoint the issue. However, since there doesn't seem to be anything in your code that explains the failures you're experiencing, I guess we need to go looking elsewhere instead of guessing blindly (and badly (including not reading the question)).
Makeshifts last the longest.
| [reply] [Watch: Dir/Any] |
|
| [reply] [Watch: Dir/Any] |
|
| [reply] [Watch: Dir/Any] |
Re: open vs. sysopen
by sgifford (Prior) on Dec 27, 2003 at 06:49 UTC
|
The first step I would try in debugging is using strace or truss to see what arguments are really being passed to the system open function. That should point you in the right direction.
Although this theory has already been debunked, the behavior you're seeing is consistent with O_WRONLY, O_TRUNC, and O_CREAT being undefined or zero. You could try printing the results out before calling sysopen, just to make sure:
print "Flags are ",O_WRONLY|O_TRUNC|O_CREAT,"\n";
On my system, the result is 577.
Also, you've tried the code with changing $self->ascii_error to just die, and with changing $ggg to a fixed value. Why don't you post the exact script you're using with these changes, in a way that any of us can just cut-n-paste to see if we get the same error (instead of making these same changes ourselves, possibly slightly differently than you did)?
| [reply] [Watch: Dir/Any] [d/l] [select] |
Re: open vs. sysopen
by !1 (Hermit) on Dec 26, 2003 at 19:39 UTC
|
Just curious: what does $ggg contain? Did it contain spaces prior? Does adding print "Exists$/" if -e $ggg; print exists? Your error is right there: No such file or directory. I'm very suspicious of $ggg.
| [reply] [Watch: Dir/Any] [d/l] |
|
| [reply] [Watch: Dir/Any] |
Re: open vs. sysopen
by xenchu (Friar) on Dec 26, 2003 at 18:30 UTC
|
sysopen HANDLE, $filename, O_WRONLY|O_CREAT|O_TRUNC;
Not a great difference I admit, but it may be significant. The sysopen examples I can find do not use parentheses between open command and filehandle. Easy enough to test at any rate. And you are not trying to use open and sysopen on the same file are you? (Didn't think so.)
It would help if you would include the entire error message in your next post.
HTH,
xenchu
The Needs of the World and my Talents run parallel to infinity.
| [reply] [Watch: Dir/Any] [d/l] [select] |
|
It would help if you would include the entire error message in your next post.
I changed ascii_error() to die() and recieved the following error:
ERROR: No such file or directory at /usr/lib/perl5/site_perl/CG/Binary.pm line 479.
-sheep
| [reply] [Watch: Dir/Any] |
|
Easy enough to test at any rate
And easy enough for you to test to find out that parentheses around
the arguments are not a problem. You could also check the docs and
notice that all the code examples in perlopentut, as well
as the examples of sysopen in the open documentation *all* use
parentheses.
Perl is a programming language, not a guessing game. You might
as well have asked if the OP walked around his chair three times
chanting bits of the Katha Upanishad before running the code. Not
a big difference, and easy enough to test right?
| [reply] [Watch: Dir/Any] |
open vs. sysopen SOLVED (partially)
by sheep (Chaplain) on Dec 27, 2003 at 20:08 UTC
|
Hello again,
The problem is solved, but I have to confess I still don't know what was causing it.
I followed sgifford's idea and oddingly got 513 as a result. On all systems, I got access to, the result was 577.
As I had to finish the code and have it working by this afternoon, I gave up proper debugging and blindly reinstalled relevant modules. (I know, I know - shame on me!)
Fresh Fcntl.pm install fixed my problem.
It wasn't an issue with the Perl binary package in Slackware - default package was removed and Perl 5.8.2 was installed from the source code.
I cannot guarantee nobody was messing with Fcntl.pm module (not only I have access to this system), but it seemed to me so improbable and absurd that I didn't bother with checking it.
Anyhow, I would like to thank all of you for your help and ideas, and also say sorry for not fixing it the proper way finding the source of the problem.
Unfortunatelly this time (even though the problem is fixed):
sheep - perl : 0 - 1
But I will see you again perl!
-sheep
| [reply] [Watch: Dir/Any] |
|
Not to re-open an old wound, but I ran across something this weekend which might be relevant: I was porting a Perl script which I wrote from Win32 systems to both MacPerl and to FreeBSD, and found that my open calls, such as
open(FH, '>', 'Myfile.txt');
needed to be rewritten as
open (FH, '>Myfile.txt');
The error message I was getting was "too many arguments", so this may be something entirely different from the above problem, but it did make me come back and have a look at this thread. Anyway, here it is, just in case it helps someone. | [reply] [Watch: Dir/Any] [d/l] [select] |
|
Sorry? Are you saying that you couldn't use the 3-arg open on Win32?
If so, could you post an example program that demonstrates that.
Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
"Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon
| [reply] [Watch: Dir/Any] |
Re: open vs. sysopen
by jsprat (Curate) on Dec 26, 2003 at 21:37 UTC
|
I'd guess that there's no use POSIX; in the snippet. POSIX.pm is where the O_WRONLY, O_TRUNC and O_CREAT constants are defined.
If my guess is right, you also need to use strict; and use warnings; (see Use strict warnings and diagnostics or die for a good discussion of this), which would point you to the real error - the barewords, O_*. Update: Strike obviously incorrect info
| [reply] [Watch: Dir/Any] [d/l] [select] |
|
I do use both: use warnings; and use strict;.
Even though I was using $! to get the error message, I changed ascii_error() to die() supplying the full error in a reply to one of the posts above.
As to the rest of the suggestions the previous reply to your post explains me.
Thanks,
-sheep
| [reply] [Watch: Dir/Any] |
|
| [reply] [Watch: Dir/Any] |
Re: open vs. sysopen
by TomDLux (Vicar) on Dec 27, 2003 at 15:13 UTC
|
Does $ggg contain anything?
Does $ggg specify a file which exists? Or just something similar to the name of a file that exists.
Are you looking in the correct directory?
--
TTTATCGGTCGTTATATAGATGTTTGCA
| [reply] [Watch: Dir/Any] |