Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run a jar file from powershell

I want to run a jar file from powershell. Till now I have been able to find this:

Start-Process -FilePath java -ArgumentList '-jar Upload_Download.jar FilePickupPath= $pickuppath FileDownloadPath= $download' -PassThru -RedirectStandardError E:\stderr.txt 

Some how this is not working. Any suggestions?

like image 476
Akki Avatar asked Oct 28 '25 17:10

Akki


1 Answers

Powershell has multiple string quotation characters that behave different ways. The double quote " allows evaluations within the string whilst the single quote ' doesn't.

As a practical example:

$foo=42
write-host "The foo: $foo"
# Prints The foo: 42
write-host 'The foo: $foo'
# Prints The foo: $foo

The command uses single quote like so, (backtick is used to split the code into screen friendly format)

Start-Process -FilePath java `
-ArgumentList '-jar Upload_Download.jar FilePickupPath= $pickuppath fileDownloadPath= $download' `
-PassThru -RedirectStandardError E:\stderr.txt 

This will pass literally $pickuppath and $download. The intention is likely to pass $pickuppath and $download's values.

In order to resolve the issue, use double quotes.

like image 118
vonPryz Avatar answered Oct 31 '25 12:10

vonPryz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!