JUCE generated Shell script is behaving totally insane

This is not 100% JUCE related, but maybe someone can help me out here. I need to run a little shell script from my JUCE app which tells the Introjucer to resave a project and xcodebuild to compile it.

This is basically the content:

project="Demo Project"
cd "`dirname "$0"`"
"/Applications/The Introjucer.app/Contents/MacOS/Introjucer" --resave AutogeneratedProject.jucer
echo Compiling VST / AU Plugin $project ...
xcodebuild -project "Builds/MacOSX/Demo Project.xcodeproj" -configuration "Release"
echo Compiling finished. Cleaning up...

In my app, I create a file (using File.replaceWithText()) and this line to run the code:

String command = "open \"" + batchFile.getFullPathName() + "\"";

int returnType = system(command.getCharPointer());

The batch file is written to the same directory as the .jucer file (so that I can use relative paths).

However, the script does not work (even not when executing it by double click), but yields this error message:

christophhart$ /Volumes/Shared/Development/HISE\ modules/extras/demo_project/Binaries/batchCompileOSX ; exit;

/Volumes/Shared/Development/HISE modules/extras/demo_project/Binaries/batchCompi: command not found

/Volumes/Shared/Development/HISE modules/extras/demo_project/Binaries/batchCompileOSX: line 3: cd: /Volumes/Shared/Development/HISE modules/extras/demo_project/: No such file or directory

Could not find file: /Users/christophhart/AutogeneratedProject.jucer

/Volumes/Shared/Development/HISE modules/extras/demo_project/Binaries/batchCompi: command not found

It seems like it cuts the lines of the script (and even the start command from 'batchCompileOSX' to 'batchCompi'. 

But now comes the weird part: If I create a new text file (in Sublime Text 3), paste the content of the JUCE generated shell script and run this file, everything works and makes me want to scream "Go home OSX, you're drunk".

I checked file permissions (also executable permissions) as well as encoding (UTF-8) and line endings (I tried both "\n" and "\r\n").

Even if I reduce the content (of the JUCE generated script file) to the minimum:

"/Applications/The Introjucer.app/Contents/MacOS/Introjucer" 

still no luck. I am on OSX 10.11.2 if that could make any difference.

OK, I think I found the cause: FileMerge says the line endings differ: CRLF (Windows) for the autogenerated file from JUCE and "LF" for the normal file. 

But how can I get a real Unix style line ending? Normally, using "\n" (and not "\r\n") should be enough, but no matter what I use, it's still the CRLF ending type.

I even tried:

    FileOutputStream fos(batchFile);

    fos.writeText(batchContent, false, false);

But still the same error.

​Running the "tr" program as system call before running the script fixes the problem:

String lineEndChange = "tr -d '\r' < \"" + tempFile.getFullPathName()+"\" > \"" + batchFile.getFullPathName() + "\"";


But I still feel stupid for not solving this within C++...

What's wrong with something as simple as

fos.writeText (batchContent.replace ("\r\n", "\n"), false, false);