How do I get the parent command in Windows command line?

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.

  • Gitignore won't ignore .vs folder for Visual Studio 2015 RC on Windows7/8
  • fatal: cannot create directory at ' ': No such file or directory
  • Git Fetch returns 'fatal: I don't handle protocol https' in windows
  • Android Studio Path to Git executable
  • Git push to LAN repo stalls or stops without error
  • What are the commands for using Git Bash in Windows e.g. when in git diff mode?
  • Git bash giving error of warning: unable to rmdir
  • Git Pull from Openshift using Windows: Invalid refspec
  • One Solution collect form web for “How do I get the parent command in Windows command line?”

    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.

    Git Baby is a git and github fan, let's start git clone.