Ugh powershell...
Ok I've been reading a lot of other answer but none of them work.
What I want to do is have a powershell script that will open a jar or open a jar with a argument. This should be so simple but I can't figure out the correct way do this easily with the powershell documentation from Microsoft...
runprogram.ps1
#Pseudocode
$PathToApp = "C:\App"
IF $PathToApp exist THEN
IF no additional argument THEN
goto PathToApp
Start-Process java -jar app.jar
ELSE IF additional argument THEN
goto PathToApp
Start-Process java -jar app.jar $arg
ENDIF
ELSE
print("Error path to app not set...")
ENDIF
then I should be able to wrtie ./runprogram.ps1 or ./runprogram.ps1 file.txt
Based on other stackoverflow post I'm sure a simple answer to this would help not only myself but many others.
Thank you for reading. And even if you don't provide a simple way to do this could you point me to some good similar examples that I could peace together. Since I and I'm sure others find powershell to be cumbersome to learn to do a simple task like this...
EDIT: In case anyone ever finds this post in the future here is something that works I made.
param(
[string]$OpenFile
)
$AppPath = "C:\App.jar"
#Check if path exist
if (-not(Test-Path $AppPath)) {
write-error "Path to app not found..."
} else {
if(-not($OpenFile)) {
Start-Process -FilePath java.exe -ArgumentList "-jar $AppPath"
} else {
Start-Process -FilePath java.exe -ArgumentList "-jar $AppPath $OpenFile"
}
}
I hope this helps someone else.