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
- Permission Denied (publickey) - Git Bash on Windows
- How to enable command line for Git
- Nginx git server returns error 500
- How to set up Git as VCS on windows workstation/server for web projects(ASP)?
- Scan for changed files
- How do I execute a .bat from git bash and then return to the console?
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.