python - send remote shell command and retrieve its output -


because unable find library following started heading out write own. i'm unable find solution problems, though, , hope here maybe has suggestion.

what want this. send normal shell command ls -al <some path> , want output (stdout , stderr) in same fashion , order appear in terminal emulator when writing command. catch is, don't want run shell command on computer i'm using, remotely via ssh or serial connection. put way, when calling ls -al <some path> 2>&1 >/tmp/out want remotely receive contents of /tmp/out without interruption or changes.

the problem is, serial connection always, ssh connection depending on choice of library, terminal command chars \x1b[k mixed output. unable find creating these commands, why nothing consuming them already, , don't know how go consuming of them myself (there lot, naive approaches won't work).

why problem special characters in output? want compare in python code if output has string ala if expected_output == output, or @ least use regular expressions. there nothing regular when , why these characters appear. simple command ls -al <something> might result in whole ssh connection breaking down (supposely because of these characters, @ least sure because don't know enough understand what's problem).

how go solving ultimate goal of sending commands remotely , receiving output? how solve 1 of mentioned subproblems (ssh connection speaks me terminal, consuming randomly appearing special characters without interpreting them, etc)?

ps: there many things i've tried, while writing found them many list them here. nothing led desired end result, though. quite complex problem, because there seem things involved not traceable (like how many (pseudo-)terminals involved) , others never documented (some of terminal handling seems come time, actual typewriter connected computer).

you have type of library.try

pexpect.

you need spawn pexpect child making ssh connection computer want make connection to.then can send commands , see ouput using .before functionality.

example:

child = pexpect.spawn('ssh admin@192.168.33.40') child.expect ('password:') child.sendline (mypassword) child.expect('#') # or expect `$`. child.sendline('<your command>') child.expect('#') print child.before 

ref:http://pexpect.sourceforge.net/pexpect.html

p.s there's paramiko same though havent used it.


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -