I have to deploy a war file in a location in D:\\Temp\\$todaydate
in command prompt as Admin using PowerShell, so my command should open the cmd prompt as admin in path D:\\Temp\\$todaydate
run Javapath "\\apps\\wsserver\\9.0\\base\\java\\8.0\\bin\\jar.exe" -cvf foo.war`
I have tried using Start-Process -Verb "RunAs"
but since I am new to PowerShell I couldn't finish the code
Start-Process -java "jar.exe" -ArgumentList "/K cd /d D:\temp\$todaydate" -Verb "runas"
My guess $todayDate
shall be the actual date. You can try to use the call operator (&) to invoke Java.
$d =((get-date).ToShortDateString())
$dashDate = $d -replace "/", "-"
$dPath ="D:/temp/$dashDate"
New-Item $dPath - ErrorAction SilentlyContinoue
Push-Location
Set-Location $dPath
# Use absolute path to Java.exe and war file in below statement
& "java.exe -cvf foo.war"
Pop-Location
If you need to resolve variable names when calling Java use invoke-expression instead the call operator.
Runs a command, script, or script block. The call operator, also known as the "invocation operator," lets you run commands that are stored in variables and represented by strings or script blocks.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.