Tem*_*lar 5 python grep pipe paramiko
我如何在paramiko中运行管道命令?我这样做: -
statement = 'grep thing file | grep thing2 | tail -1'
last_msg = conn.execute(statement)
Run Code Online (Sandbox Code Playgroud)
我得到的输出grep thing file.
因为grep不知道如何处理|.准备好一些讨厌的逃脱:
statement = """sh -c 'grep thing file | grep thing2 | tail -1'"""
Run Code Online (Sandbox Code Playgroud)
这会在另一侧创建一个shell,并要求它解释该字符串grep thing file | grep thing2 | tail -1.单引号是必要的,因为sh -c只接受一个参数.
这样,shell将为您创建管道,运行所有命令.并且您最好确保文件名file不包含空格.如果是的话,试试吧"file".
| 归档时间: |
|
| 查看次数: |
2680 次 |
| 最近记录: |