1

I have a program in my Linux machine. When I run the program, I'm asked a few questions like this:

root@bgserver7:~/userinfo# ./userinfo 1
Enter your name:

i have this code to read ssh with paramiko:

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))

I want to run the ./userinfo 1 program and answer this subprocess program, but out_subprocess and read_shell can't read this.

How can I do it? Thanks.

aschultz
  • 1,658
  • 3
  • 20
  • 30
shahab47
  • 45
  • 8

0 Answers0