0

I am using PowerShell script to start multiple Java application.

$app = Start-Process -FilePath java -ArgumentList "-jar $path_to_jar" -PassThru

it's working as expected.

But I also have to search a particular Java process and stope/close it.
I cant use process id ($app.ID) as stop script will be a different script.

Can I have some custom name/identifier to these Java process to get a particular process ? like if I can fetch a java process by JAR name etc.

Not sure but in Linux environment I have seen use of -DAPP_INSTANCE_NAME flag , that might be a custom flag to identify a process.

Any help is apricated.

Posto
  • 7,362
  • 7
  • 44
  • 61

2 Answers2

0

Finally I am using JPS , it's command

& jps -v 

returning all the details like jar name etc. and that result I am using for filtering out the process id.

Posto
  • 7,362
  • 7
  • 44
  • 61
0

leave a snippet here

Get-Process -Id ((jps) | Select-String -Pattern '([0-9]+)\s+foo\.jar').Matches.Groups[1].Value | Stop-Process

if you not sure if this process exist

(jps).where({$_ -match '^([0-9]+)\s+foo\.jar'})
# add check here
Get-Process -Id $Matches.1 | Stop-Process

Note for Windows user : On my computer , Get-WmiObject -Query ...(wmic in powershell) sometimes return empty CommandLine property. And this jps way works fine.

RadND
  • 1
  • 1