Comments (3)
You can make it a bit shorter and better. Some improvements:
- no
call
for binaries %~f0
instead%~dpn0.bat
- add
>&2
to output error messages to STDERR. goto :EOF
is transparent for%ERRORLEVEL%
, so no needs toexit /b %ERRORLEVEL%
. But you can leave your original command for sure.- no dancing around
batch_start_label_cs_hybrid
now. It's obviously shorter and clearer: the caret in@rem ^
tells cmd.exe to concatenate it with the next line before executing, thus you don't need togoto :LABEL
and:LABEL
and too complicated code to exclude the first line. And if you want, you can shorten it further replacingfindstr /v /b "@rem ^"
withmore +1
.
@rem ^
/*
@echo off
if exist "%~dpn0.exe" (
"%~dpn0.exe" %*
goto :EOF
)
setlocal
:: Additional options to csc.exe (like /r:"references")
set CSC_OPS=
:: Runner options
set CS_FAIL_EXIT_CODE=1001
:: find csc.exe
set "csc="
for /r "%SystemRoot%\Microsoft.NET\Framework\" %%# in ("*csc.exe") do set "csc=%%#"
if not exist "%csc%" (
echo Error: no .net framework installed>&2
exit /b %CS_FAIL_EXIT_CODE%
)
findstr /v /b "@rem ^" "%~f0" >"%~f0.cs" || (
echo Error: fail to prepare executable>&2
exit /b %CS_FAIL_EXIT_CODE%
)
"%csc%" /nologo %CSC_OPS% /out:"%~dpn0.exe" "%~f0.cs" || (
exit /b %CS_FAIL_EXIT_CODE%
)
del "%~f0.cs"
"%~dpn0.exe" %*
goto :EOF
*/
using System;
public class Program
{
public static int Main(string[] Argv)
{
Console.WriteLine("Hello, world!");
return 42;
}
}
from batch.scripts.
Thanks. Probably I'll have time to check it at the weekend. Is really @rem ^
works fine at the beginning of the file? It is also possible to use msbuild to reduce the redundant output: https://github.com/npocmaka/batch.scripts/blob/master/hybrids/.net/msbuild/checkPort.bat
from batch.scripts.
Is really @Rem ^ works fine at the beginning of the file?
Yes. before publishing I tested it.
from batch.scripts.
Related Issues (20)
- Screen capture with specified window title capture the foreground window HOT 1
- How can I get the response HOT 3
- Post Fields by command line HOT 2
- Click does not work when cmd is not selected
- Trying to get response using winhttpjs.bat but there is something wrong I'm doing HOT 3
- sendKeys.bat does not work if the window is minimized
- Run JsonExtractor Without any other file HOT 9
- Comments for screenCapture.bat ? HOT 2
- How to continue scripting in windows batch?
- .
- ( I'm a beginner ) I need help with a program I want to write HOT 2
- bat2exe.bat
- Why is the __COMPAT_LAYER variable defined? HOT 1
- Fix Suggestion
- "find" function in binaryTree.bat file doesn't work
- how do you replace multiple strings with replacer.bat ?
- Microsoft Defender Alert! HOT 2
- Change the extensions from .bat to .cmd
- exe2bat Reverse HOT 1
- Virus? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from batch.scripts.