minecraft-server-kb01-de/mc-java/start.ps1

27 lines
1 KiB
PowerShell
Raw Normal View History

2023-03-25 15:08:14 +01:00
$basedir=(Get-Location)
$buildtools=$basedir.Path + "\..\.tools\buildtools"
$version="1.19.4"
$java=$env:JAVA_HOME
2023-03-25 15:08:14 +01:00
if ( $args.count -eq 0 ) {
2023-03-25 15:08:14 +01:00
Set-Location ($basedir.Path+"\server")
& $java\bin\java.exe -jar (".\spigot-"+$version+".jar") --nogui
}
elseif ($args[0] -eq "background") {
$serverProcess = New-Object System.Diagnostics.ProcessStartInfo;
$serverProcess.FileName = ($java + "\bin\java.exe"); #process file
$serverProcess.Arguments = ("-jar " + $basedir.Path + "\server\spigot-"+$version+".jar --nogui");
$serverProcess.WorkingDirectory = ($basedir.Path+"\server");
$serverProcess.UseShellExecute = $false; #start the process from it's own executable file
$serverProcess.RedirectStandardInput = $true; #enable the process to read from standard input
$p = [System.Diagnostics.Process]::Start($serverProcess);
Start-Sleep -s 50 #wait 2 seconds so that the process can be up and running
$p.StandardInput.WriteLine("stop"); #StandardInput property of the Process is a .NET StreamWriter object
}
2023-03-25 15:08:14 +01:00
Set-Location $basedir