Piped commands in paramiko
问题 How do I run piped commands in paramiko? I'm doing this: statement = 'grep thing file | grep thing2 | tail -1' last_msg = conn.execute(statement) and I get the output of grep thing file only. 回答1: Because grep doesn't know how to handle | . Get ready for some nasty escaping: statement = """sh -c 'grep thing file | grep thing2 | tail -1'""" This creates a shell on the other side, and asks it to interpret the string grep thing file | grep thing2 | tail -1 . The single quotes are necessary since