In a Unix shell, I can get the parent command using ps -ocommand= -p $PPID
. How can I do the same from the Windows shell?
I need this for a Git pre-commit hook that detects whether the commit was initiated with the --amend
flag.
In a Unix shell, I can get the parent command using ps -ocommand= -p $PPID
. How can I do the same from the Windows shell?
I need this for a Git pre-commit hook that detects whether the commit was initiated with the --amend
flag.
A crude way of doing this is by looking up current PID using a title query.
title ABC
for /f "tokens=2" %%P in ('tasklist /V ^| findstr "ABC"') do set CurrentPid=%%P
for /f "tokens=2 skip=1" %%P in ('wmic process where ProcessId^=%CurrentPid% get Caption^,ParentProcessId^,ProcessId') do set ParentProcessId=%%P
wmic process where ProcessId=%ParentProcessId% get CommandLine
There is a lot that can be optimized there.