As the .net framework comes with three default compilers jsc.exe - for javascript , csc.exe - for c# and vbc.exe for visual basic .net I've tried to create a hybrid for each of them (with "hello world " examples only).
jscript.net is the best option according to me - does not require a main method or wrapping something in a class and also supports @if directive - http://msdn.microsoft.com/en-us/library ... xa(v=vs.90).aspx (as well as jscript) so the notorious jscript/bat technique can be used for clear output .It's not so powerful language as C# ,but for a script purposes I think it's better (beware that the WScript methods are not accessible here):
Code: Select all
@if (@X)==(@Y) @end /* Harmless hybrid line that begins a JScript comment
@echo off
setlocal
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 jsc=%frm%%netver%\jsc.exe
call %jsc% /nologo /out:"%~n0.exe" "%~dpsfnx0"
%~n0.exe
endlocal
exit /b 0
*/
print("Hello World!");
c# more code is required compared to the jscript.net and have unavidable "//>nul 2>nul||" print (may be could be remoted with some namespace definition??).Nothing new here:
Code: Select all
//>nul 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
call %csc% /nologo /out:"%~n0.exe" "%~dpsfnx0"
%~n0.exe
endlocal
exit /b 0
*/
public class Hello
{
public static void Main()
{
System.Console.WriteLine("Hello, C# World!");
}
}
Visual Basic - uses similar technique as this here http://stackoverflow.com/a/16622325/388389 .But cannot reduce the initial print of " '1>nul 2>&1 || " , because here is not possible to define a method outside of a class/module or whatever is called :
Code: Select all
'>nul 2>&1||@copy /Y %windir%\System32\doskey.exe '.exe >nul
'& @echo off
'& setlocal
'& 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
'& set vbc=%frm%%netver%\vbc.exe
'& call %vbc% /nologo /out:"%~n0.exe" "%~dpsfnx0"
'& %~n0.exe
'& endlocal
'& exit /b 0
Imports System
Public Module modmain
' Main is the application's entry point.
Sub Main()
' Write text to the console.
Console.WriteLine ("Hello World using Visual Basic!")
End Sub
End Module