I am trying to run a program and get its PID so that I could terminate the program if it hung up during execution. I could not kill the program with program name since there will be more than one program running on the PC. I come across forums and got the suggestion of wmic usage but I could not get the output of the program with calling it with wmic.
It is about the same problem as mentioned in this post: Remote Netstat to STDOUT with WMIC?
I tried this command as suggested to execute the program and output:
wmic process call create "cmd /C > C:\temp\test.txt 2>&1 netstat.exe -ano"
With this command, I am able to retrieve the output of the program but then the program is actually called from another cmd? This defied the original purpose why I had initially trying to use wmic.
Anyone could tell if I have another way to do get the output or another way to call a program from batch, get its PID and the output redirection of the program called?