0

I would love to have a little problem solved. I know that it's not the best way to debug a piece of code with possible warnings, but I love to debug all the time when I have a little break between to ideas. I just found out about mono and the possibility to compile C# code running on Mac OS X Mountain Lion. I integrated it in the CodeRunner app, and it works without any problems. However, if there appears a warning in the code, it does not work.

For example, I tried to compile a code that creates one integer (nothing more than that) and it was not debugging because of that warning. I'm getting this error message:

Untitled.cs(9,29): warning CS0219: The variable `test' is assigned but its value is never used
Cannot open assembly 'Compilation succeeded - 1 warning(s)
Untitled.exe': No such file or directory.

Someone may know how to deal with that. I know it's not an essential feature, but I would love to debug the code even with some unused variables.

The content of the compilation script file:

#!/bin/bash

enc[4]="UTF8"            # UTF-8
enc[10]="UTF16"            # UTF-16
enc[5]="ISO8859-1"        # ISO Latin 1
enc[9]="ISO8859-2"        # ISO Latin 2
enc[30]="MacRoman"        # Mac OS Roman
enc[12]="CP1252"        # Windows Latin 1
enc[3]="EUCJIS"            # Japanese (EUC)
enc[8]="SJIS"            # Japanese (Shift JIS)
enc[1]="ASCII"            # ASCII


rm -rf "$4"/csharp-compiled
mkdir "$4"/csharp-compiled
#mcs is the Mono CSharp Compiler

file="$1"
length=${#file}
first=`expr $length - 3`
classname=`echo "$file" | cut -c 1-"$first"`
#echo -out:"$4"/csharp-compiled/"$classname".exe "$1"
dmcs -out:"$4"/csharp-compiled/"$classname".exe "$1"
status=$?

if [ $status -ne 0 ]
then
exit $status
fi

#echo "$4"/csharp-compiled/

currentDir="$PWD"
cd "$4"/csharp-compiled/
files=`ls -1 *.exe`
status=$?
if [ $status -ne 0 ]
then
exit 1
fi

cd "$currentDir"
for file in $files
do
mv -f "$4"/csharp-compiled/$file "$file"
done

# Otherwise output the name of the input file without extension (this should be the same as the class name)
file="$1"
length=${#file}
first=`expr $length - 3`
classname=`echo "$file" | cut -c 1-"$first"`
echo $classname".exe"
exit 0
Matthew Rankin
  • 457,139
  • 39
  • 126
  • 163
TurboFish
  • 7,789
  • 4
  • 18
  • 27
  • 1
    This looks like your integration in code runner is wrong: the compiler output appears to be incorrectly treated as part of the file name. Can you give details about how you've attempted to make it work? –  Oct 02 '12 at 14:52
  • OK, here are the settings. I enabled "language uses compilation script". I/O Encoding is UTF-8. The run Command is 'mono $compiler'. Syntax mode is 'C#' and the file extension is cs. The content of the compilation script is taken from a tutorial. May I post them if you're interested or there might be the problem. – TurboFish Oct 02 '12 at 18:29
  • Sry fot the doublepost, two more things: The settings I posted are the settings in the language tab of the preferences. I also updated the first post with the content of the compilation script file. – TurboFish Oct 02 '12 at 18:37
  • Could you give `>&2` a try? Add it at the end of the `dmcs` line. It would make any output from the compiler show up on stderr, which should make sure it doesn't get misinterpreted. –  Oct 02 '12 at 18:38
  • wow it seems to be working. Now I just receive the warning and the message 'Compilation completed'. Thank you very much. The little thins are important :) I'm new to StackOverflow. Is there any possibility to give you any credit for that comment? – TurboFish Oct 02 '12 at 18:53
  • Glad it helped, I've posted it as an answer. You should be able to accept it as the answer to this question, if you like. –  Oct 02 '12 at 19:47

3 Answers3

1
dmcs -out:"$4"/csharp-compiled/"$classname".exe "$1"

dmcs puts some messages on stdout, and some on stderr. CodeRunner expects stdout to only contain the output file name, nothing else, so to make that happen, >&2 can be used to redirect everything else to stderr.

dmcs -out:"$4"/csharp-compiled/"$classname".exe "$1" >&2
1

This worked for me on Sierra with current Mono and CodeRunner versions:

Language compile script:

file=$CR_FILENAME
/Library/Frameworks/Mono.framework/Versions/Current/bin/mcs "$CR_FILENAME" >&2
status=$?
if [ $status -ne 0 ]
then
exit $status
fi
echo $file | sed -e "s/\.cs/.exe/"
exit 0

Run command:

PATH="/Library/Frameworks/Mono.framework/Versions/Current/bin:$PATH"; mono $compiler
Markus
  • 11
  • 1
0

In MS compiler thre is a way to hide warnings

Pragma Warning Preprocessor Directive

#pragma warning disable 219
var test = "";
#pragma warning restore 219

It might help you.

Anton Sizikov
  • 9,105
  • 1
  • 28
  • 39
  • Thank you for that quick response, but I don't want to hide the warnings. It's ok when the app tells me that there could be something wrong, but the problem ist that it's not debugging because of one tiny warning. – TurboFish Oct 02 '12 at 14:16
  • You can turn in on back after debugging. – Anton Sizikov Oct 02 '12 at 14:17
  • OK I just tried it and it works for me, so it could be one little workaround. Thank you very much, Mr Sizikov. I'll keep the question up a little bit. Maybe there is someone who knows one even better solution. – TurboFish Oct 02 '12 at 14:22