Re: self-compiled .net hybrids
Posted: 24 Jun 2015 08:03
Without redundant output:
though if there are `echo`-es before the c# part you'll need to change the cursor position.And wont work if the file is redirected to a file.Also I'm not sure if Console.CursorTop is available in .net 2 and 3
Code: Select all
// 2>nul||@goto :batch
/*
:batch
@echo off
setlocal
:: find csc.exe
set "frm=%SystemRoot%\Microsoft.NET\Framework\"
for /f "tokens=* delims=" %%v in ('dir /b /a:d /o:-n "%SystemRoot%\Microsoft.NET\Framework\v*.*"') do (
set netver=%%v
goto :break_loop
)
:break_loop
set csc=%frm%%netver%\csc.exe
:: csc.exe found
if not exist %~n0.exe (
%csc% /nologo /out:"%~n0.exe" "%~dpsfnx0" >nul
)
%~n0.exe
echo -- redundant output has been cleared --
endlocal
exit /b 0
*/
public class Hello
{
public static void Main() {
ClearC();
System.Console.WriteLine("Hello, C# World!");
}
public static void ClearC() {
try {
System.Console.CursorTop = System.Console.CursorTop - 1;
System.Console.Write(new string(' ', System.Console.BufferWidth));
System.Console.CursorTop = System.Console.CursorTop - 1;
} catch (System.IO.IOException e) {
}
}
}
though if there are `echo`-es before the c# part you'll need to change the cursor position.And wont work if the file is redirected to a file.Also I'm not sure if Console.CursorTop is available in .net 2 and 3