Author Posts

January 1, 2012 at 12:00 am

by chz013 at 2013-02-01 16:50:51

Hi All

How do we script with multiple arguments ?
We think the 1-liner argument in $argument below is a little too long.

$arguments = @(
"-Xmx512m -jar C:\test\test.jar -mode=silent -smallxml=C:\test\test.xml -log=C:\test\test.log"
)
$proc = Start-Process "java" -ArgumentList $arguments -Wait -PassThru

Is there a case statement equivalent in powershell to find the exit code of $proc ?
How do we do that ?

Thanks

by DonJ at 2013-02-02 10:06:18

Well, in terms of the argument being too long, I don't know what to tell you. If that's the argument that the command needs, it doesn't really matter how long it is. And, that's the correct way to pass the argument. You don't need to make it into an array – PowerShell would do that implicitly. I mean, you could use an actual array @("-Xmx512m","-jar c:\test\test.jar","-mode=silent") and so on. But that won't make it shorter.

PowerShell does have a Switch construct that works similarly to a case construct. Read "about_switch" in the shell's help.