簡體   English   中英

如何從python腳本調用git clean -df命令

[英]How can I call the git clean -df command from a python script

我是python的新手,正在嘗試在python腳本中使用git命令。 要求是我需要在我的python腳本中調用一些git命令,例如git clean和git reset命令。 我需要為此使用子進程,因為我不能使用任何外部庫(如GitPython)。

任何幫助,將不勝感激

謝謝。

你可以像下面一樣使用它

import shlex
import subprocess 

command= "git clean -df" # you can paste any command here
comm=shlex.split(command) # This will convert the command into list format

proc=Popen(comm) # This will execute your command

有關更多詳細信息,請參閱此處

https://docs.python.org/2/library/subprocess.html

暫無
暫無

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

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