簡體   English   中英

如何在Windows命令行中獲取父命令?

[英]How do I get the parent command in Windows command line?

在Unix shell中,我可以使用ps -ocommand= -p $PPID獲得父命令。 如何在Windows Shell中執行相同操作?

我需要一個Git預提交鈎子來檢測提交是否使用--amend標志啟動。

粗略的方法是使用標題查詢查找當前的PID。

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

那里有很多可以優化的地方。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM