View Full Version : Get the return of "fopen"
Nicool 03-08-2003, 06:24 PM If an error occurrs while attempting to open the file, fopen will return zero From the Doc.
How to get the "return" of this function? How to make my conditionnal? A query action?
$session=`fopen $fileName "w"`;
fwrite $session $content;
fclose $session;
/*
if ( return is "0" ) {
error "An error has occured during writing the file";
}
*/
:wavey:
|
|
luminis
03-08-2003, 07:48 PM
Have you tried:
if ( $session = 0 ) {
......
}
The 0 shouldn't be double quoted because the return of fopen is an int value, not a string. Hope that helps. :)
Nicool
03-08-2003, 07:53 PM
Thanks luminis... I see how it's simple and evident :)
(For my if, it was just a sentence to explicite de zero value)
Thanks
Nicool
03-08-2003, 08:04 PM
// Notes : Don't forget the quotes in writing your strings. Use "/" (and not "\") for the path. Add the extension you want (*.txt, *.bat, *.3d).
global proc writeTextFile(string $fileName, string $content) {
$session=`fopen $fileName "w"`;
fwrite $session $content;
fclose $session;
if ($session=0) {
error "An error has occured during writing the file";
}
}
rhythmone
03-08-2003, 09:42 PM
I could be wrong but shouldn't it be:
if ($session==0)
if ($session=0) --> doesn't this set $session equal to zero???
One other note - along time back I was doing this in TCL and I remember that I was getting wierd results until I remembered to close the opened file within the script. I wonder if mel is the same.
Nicool
03-08-2003, 10:07 PM
Yes, sorry, it's true about the ==
For the C-style file write function, I've learn it by working on PHP ;)
jschleifer
03-08-2003, 11:17 PM
Originally posted by rhythmone
I could be wrong but shouldn't it be:
if ($session==0)
if ($session=0) --> doesn't this set $session equal to zero???
One other note - along time back I was doing this in TCL and I remember that I was getting wierd results until I remembered to close the opened file within the script. I wonder if mel is the same.
yeah, in mel that will set $session to 0.
-jason
CGTalk Moderation
01-14-2006, 02:00 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.