我想通過ssh終止一個進程。 現在,當直接終止進程時,請參閱init中的註釋行,該進程在遠程主機上終止。 當然,我不想立即終止,而是終止所有遠程進程。Python通過ssh終止一個進程
根據在subprocess.Popen選項「-t」,當我嘗試一下例子結束在循環終止不同的結果顯示:
如果「-t」是不集,過程是不是終止。
如果設置了'-t',過程終止,但我的終端隱藏任何輸入,任何輸入都會移動輸入行。
現在,爲什麼沒有'-t'選項,進程終止在循環?
serverThreads = []
serverscripts = []
serverscripts.append("script1")
serverscripts.append("script2")
class ServerCaller(threading.Thread):
def __init__(self, script):
threading.Thread.__init__(self)
self.script = script
self.ssh = subprocess.Popen(["ssh", '-t' , username + dataServer, self.script])
#if I terminate here without '-t' the process on the remote Host is terminated
#self.term()
def term(self):
self.ssh.terminate()
for ss in serverscripts:
serverThreads.append(ServerCaller(ss))
#if I terminate here without '-t' the process on the remote Host is NOT terminated
#if I terminate here with '-t' the process on the remote Host is terminated,
#but my terminal is screwed up
for t in serverThreads:
t.term()
使用面料或paramiko – e4c5
在我看來,這個問題是我對python缺乏瞭解,並不是說這是不可能的。終止一個子進程.Popen對我來說已經足夠了,我只是想明白爲什麼同一個對象上完全相同的方法不會做同樣的事情。 我已經看過paramiko,但它有問題,告訴我它沒有找到我的調用可執行文件,但這是另一個問題 – Vuk
它不是Python,它是ssh。編寫你自己的ssh接口就像寫一個時間解釋一樣,它會變成flappy,而且有人已經做得更好,那麼你可以做得更好。我認爲你有它的工作,並有你的答案。 '-t'強制僞tty,這有點像屏幕。我認爲可以在tty獲得博士學位。 –