Last active
June 30, 2021 10:30
-
-
Save NullPointerMaker/c9e745ad4f33d1aadb4c123159acd627 to your computer and use it in GitHub Desktop.
Launchers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Echo Off | |
@Rem Batch file launcher with pause at exit | |
SetLocal EnableDelayedExpansion | |
Title %~n0 | |
CD /D "%~dp0" | |
If /I "%1"=="Minimized" ( | |
Start /Min Cmd /C "%~dpnx0 PauseErrorOnly" | |
Exit | |
) | |
If Exist %~dp0.Cmd ( | |
Rem Command script | |
%~dp0.Cmd | |
) Else ( | |
Echo %~dp0.Cmd not found! | |
Set ErrorLevel=1 | |
) | |
Set ExitCode=!ErrorLevel! | |
Echo. | |
If /I "!ExitCode!"=="0" ( | |
If Not "%1"=="PauseErrorOnly" ( | |
Pause | |
) | |
) Else ( | |
Echo Exit Code: !ExitCode! 1>&2 | |
Echo. | |
Pause | |
) | |
Exit !ExitCode! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# BASh launcher with stdout and stderr to files | |
cd "$(dirname "${BASH_SOURCE[0]}")" || exit | |
name=$(basename "${BASH_SOURCE[0]}") | |
name=${name%.*} | |
if [ ! -x "$name" ]; then | |
# Exec | |
chmod +x "$name" | |
command="./$name" | |
elif [ ! -f "$name.jar" ]; then | |
# Java | |
command="java -jar $name.jar" | |
elif [ ! -f "$name.py" ]; then | |
# Java | |
command="python -u $name.py" | |
else | |
echo "Program file not found!" | |
exit 1 | |
fi | |
function doStart() { | |
pid=$(pidof "$name") | |
if [ ! "$pid" ]; then | |
rm "$name.out" "$name.err" | |
bash -c "exec -a $name $command &" 1>>"$name.out" 2>>"$name.err" | |
fi | |
sleep 1 | |
pid=$(pidof "$name") | |
if [ "$pid" ]; then | |
echo "$pid started" | |
else | |
cat "$name.out" "$name.err" | |
exit 10 | |
fi | |
} | |
function doStop() { | |
pid=$(pidof "$name") | |
# shellcheck disable=SC2086 | |
if [ "$pid" ]; then | |
kill $pid | |
while kill -0 $pid 2>/dev/null; do | |
sleep 1 | |
done | |
echo "$pid stopped" | |
fi | |
} | |
trap 'onCtrlC' INT | |
function onCtrlC() { | |
doStop | |
} | |
if [ "$1" == "stop" ]; then | |
doStop | |
exit | |
elif [ "$1" == "start" ]; then | |
doStart | |
exit | |
elif [ "$1" == "restart" ]; then | |
doStop | |
doStart | |
exit | |
else | |
doStart | |
tail --pid="$pid" -qf "$name.out" "$name.err" | |
fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Echo Off | |
@Rem Command script launcher with pause at exit | |
SetLocal EnableDelayedExpansion | |
Title %~n0 | |
CD /D "%~dp0" | |
If /I "%1"=="Minimized" ( | |
Start /Min Cmd /C "%~dpnx0 PauseErrorOnly" | |
Exit | |
) | |
If Exist %~dp0.Bat ( | |
Rem Batch | |
%~dp0.Bat | |
) Else If %~dp0.Exe ( | |
Rem Executable | |
%~dp0.Exe | |
) Else If %~dp0.JAr ( | |
Rem Java | |
Java -jar %~dp0.JAr | |
) Else If %~dp0.Py ( | |
Rem Python | |
Python -u %~dp0.Py | |
) Else ( | |
Echo Program file not found! | |
Set ErrorLevel=1 | |
) | |
Set ExitCode=!ErrorLevel! | |
Echo. | |
If /I "!ExitCode!"=="0" ( | |
If Not "%1"=="PauseErrorOnly" ( | |
Pause | |
) | |
) Else ( | |
Echo Exit Code: !ExitCode! 1>&2 | |
Echo. | |
Pause | |
) | |
Exit !ExitCode! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment