我的Linux机器中有一个程序。 当我运行程序时,我会被问到一些类似这样的问题:
root@bgserver7:~/userinfo# ./userinfo 1
Enter your name:
我有这段代码可以用paramiko读取ssh:
ssh_client = paramiko.SSHClient()
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh_client.connect(hostname=ip,username=name,password=password)
def std(command):
stdin, stdout, stderr = ssh_client.exec_command(command)
out_subprocess = stdout.readlines()
print ("stdout"+str(stdout.readlines()))
print ("stdin"+str(stdin))
print ("stderr = "+str(stderr.readlines()))
return out_subprocess
def read_shell(command):
remote_connection = ssh_client.invoke_shell()
remote_connection.send(command+"\n")
time.sleep(5)
output = remote_connection.recv(10240)
output = str(output)
output = output.split('\\r\\n')
return output
output = read_shell("cd userinfo")
for index, line in enumerate(output):
print("line: " + str(index) + "; " + line)
if "~userinfo#" in line :
in_dir_tabchi = True #check for current Dir
# end
if in_dir_tabchi == True:
output = read_shell("./userinfo 1")
for index, line in enumerate(output):
print("line: " + str(index) + "; " + line)
# end
out_subprocess = std("./userinfo 1")
print(str(out_subprocess))
我想运行./userinfo 1
程序并回答该子流程程序,但是out_subprocess和read_shell无法读取它。
我该怎么办?谢谢。