我正在使用python模塊Paramiko ssh到Linux框並執行兩個C程序。 程序1在觸發器上的DAQ設備上生成一個信號。它等待觸發並在5秒內終止。 程序2生成觸發器。分叉使用python paramiko
這裏是我的Python類:
class test:
server = "localhost"
username = "root"
password = "12345"
def ssh (self, cmd = ""):
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(self.server,username=self.username,password=self.password)
stdin, stdout, stderr = ssh.exec_command(cmd)
result = stdout.read().splitlines()
if len(result)!= 0:
return result
else:
return -1
test.ssh("program1")
test.ssh("program2")
的問題是程序1已被終止後,正在執行的程序2,因此不會產生任何東西。 有沒有一種方法可以比program1更快地運行program2?我試過
test.ssh("program1 &")
test.ssh("program2")
但無濟於事。如果我在兩個終端shell中手動運行這些程序,那麼它工作正常。有什麼想法嗎?
執行這兩個程序,你可以嘗試使用Python線程 – c4f4t0r