我想从powershell运行一个jar文件.直到现在我能够找到这个:
Start-Process -FilePath java -ArgumentList '-jar Upload_Download.jar FilePickupPath= $pickuppath FileDownloadPath= $download' -PassThru -RedirectStandardError E:\stderr.txt
一些如何不起作用.有什么建议?
Powershell有多个字符串引号字符,其行为方式不同.双引号"
允许在字符串中进行评估,而单引号'
则不允许.
作为一个实际的例子:
$foo=42 write-host "The foo: $foo" # Prints The foo: 42 write-host 'The foo: $foo' # Prints The foo: $foo
该命令使用单引号,(反引号用于将代码拆分为屏幕友好格式)
Start-Process -FilePath java ` -ArgumentList '-jar Upload_Download.jar FilePickupPath= $pickuppath fileDownloadPath= $download' ` -PassThru -RedirectStandardError E:\stderr.txt
这将通过字面意思$pickuppath
和$download
.其意图可能是通过$pickuppath
和$download
的值.
要解决此问题,请使用双引号.