[Python] How to read the send command output in expect script

Discussão em 'Python' iniciado por Stack, Março 18, 2025.

  1. Stack

    Stack Membro Participativo

    I have an expect script that will login to the remote server and execute a python script. In python script I have set sys.exit(1) for a certain condition so that it would stop execution when that condition is met. Is there way to know if python script stopped execution or ran fine?
    (or) is there a way to read the output that python script produces (that is I would like to read output of send "python pythonscript.py arg1\r"). Any approach is fine. Please suggest ideas

    expectscript.exp

    #!/usr/bin/expect

    eval spawn ssh -oStrictHostKeyChecking=no -oCheckHostIP=no user@******
    expect "Password:"
    send "password\r"
    expect "$username$"
    set prompt ":|#|\\\$"
    set timeout -1
    send "cd /Users/username/Documents/folder/\r"
    send "python pythonscript.py arg1\r"
    expect $prompt

    Continue reading...

Compartilhe esta Página