I have a third party application that uses .bat batch files to kick off their java applications. (It's pentaho, but not sure that matters much for what I'm doing).

I'd like to be able to get a hold of the process that it spawns to track resource usage like memory/cpu/runtime.

Trying something like

$p=Start-Process kitchen.bat -PassThru

Returns quickly, $p has a "processId" but by the time I can do anything with it it's already gone.

I can't just spin waiting for a java process because there are many running simultaneously.

Also, the primary batch file ultimately calls another batch file, adding yet another level of redirection.

In powershell:

  • How do I identify and grab ahold of my java process ultimately spawned from these batch files?
  • Is there a possibility to remove the batch files and use just pure powershell? – Elliot Labs LLC Jul 11 '19 at 16:52
  • I'm thinking of it. It's part of a 3rd party package using that as its main entry point so I was trying to keep in line with that. End of the day it's calling java.exe with the classpath jvm options and parameters it needs. – atxdba Jul 11 '19 at 23:16
  • 1
    I'm going to take a peek at the process objects when I get back to my hotel. I could have sworn there should be a child process property. if that exists, we should be able to set up an event listener to trigger a retrieval of the new child process object when a new one is launched. – Elliot Labs LLC Jul 11 '19 at 23:26
  • I wasn't able to find a child process property. The easiest way to pull this off would be to cut out the middle man and launch Java yourself. Otherwise it would be prudent to hook into the Win32 API (Advanced and not easy). So, Read the java launch args from the batch file so if it is updated it will dynamically update the launch args of your powershell launcher. This will make it so that you do not lose the original coding of your 3rd party devs, while making it extensible for your infra. – Elliot Labs LLC Jul 12 '19 at 16:19
  • Get-WmiObject win32_process | Where-Object parentprocessid -eq $p.Id could help? – JosefZ Oct 10 '19 at 16:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.