View Full Version : file writing problem between mac and windows

07 July 2005, 05:05 AM
Hey all,

I am having a bit of an issues here.

I have a mel script that calculates some data in maya and writes it to a file on my machine (Mac OS X). I then want to read this data by another piece of software on windows. The problem I am having is that the file (when viewed in wordPad) on windows adds these square characters to the file.

I would imagine this has something to do with the way that Mac and windows parse files. Any thoughts on how I can solve this issue?

thanks guys

07 July 2005, 11:57 AM
Yes, that is the way MEL writes text data to file via fwrite, every string will be ended with a null character, which appear as the black quares in the notepad.

I remember I did try for a while to find the workround, but finally gave up. I think it better to write plug-ins for file I/O. You can use C/C++ calls to read and write binary files, which is better portable cross different platforms.

07 July 2005, 04:19 PM
I was afraid of that,

I was thinking that I could write a tcl script to strip that character from the file once it is created. Although I would really like the export of the data to be a 1 click kind of process,

could I tell the tcl script to alter the data from within mel?


07 July 2005, 06:08 AM
I feel it'd be helpful to write an app to convert the text file written by MEL. What programming language you are using doesn't matter. Just read the text file, and ignore all those null characters, then write to a new file.

Hope it make sense,

07 July 2005, 07:08 AM
I checked in the maya help, it says:

The fwrite command writes the data argument in binary format to a file. Strings are written as ascii terminating with a NULL character. Note that this should not be used for writing to a text file. If you wish to write out a text file, use fprint instead as it does not terminate the written string with a null character. Only use this for binary files.

so maybe you should use fprint? Maybe that helps.

07 July 2005, 07:27 AM
$exampleFileName = ( "D:/example.txt" );
$fileId=`fopen $exampleFileName "w"`;
fprint $fileId "Hello there\n";
fclose $fileId;

Nothing changed. Still got null characters.

07 July 2005, 08:17 AM
Well I used fprint on Mac, and saved a txt file. After copying to windows, and opened using notepad, it works just like opening on mac.

I didn't have the problem.^^"

$exampleFileName = ( `internalVar -userTmpDir` + "example.txt" );
$fileId=`fopen $exampleFileName "w"`;
fwrite $fileId "Hello there\n";
fclose $fileId;

my userTmpDir is /Users/mac/Documents/temp/

and I copied the file in that dir....and it worked.

07 July 2005, 08:55 AM
Seems that MEL handles text files in a different way on Mac. I haven't tried that on Linux.

In most cases, I'd prefer using plug-in and binary file for data exchange. But still glad to get more info about the annoying null character.

It is time to learn Maya API when you find more and more limitations of using MEL - my opinion.

07 July 2005, 08:46 PM
thanks for the reply's its all really helpful.

I will definately test the fprint theory instead of fwrite and see if it works ok, however, on thing I noticed was that notepad on windows reads the current mac text file just fine. It is in wordpad that the null character shows up. I will do more testing though.

Thanks again all, and yeah, It is time to dive in to the API.


CGTalk Moderation
07 July 2005, 08:46 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.