2014-06-19 2 views
3

:파이썬, paramiko, invoke_shell 못생긴 캐릭터 나는 아래의 파이썬 코드를 실행하면

import workflow 
import console 
import paramiko 
import time 

strComputer = 'server.com' 
strUser = 'user' 
strPwd = 'passwd' 

client = paramiko.SSHClient() 
client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) 
client.connect(hostname=strComputer, username=strUser, password=strPwd) 

channel = client.invoke_shell() 
channel.send('ls\n') 
time.sleep(3) 
output=channel.recv(2024) 
print(output) 

#Close the connection 
client.close() 
print('Connection closed.') 

을 나는 추한 자와 혼합하여 원하는 출력을 얻을 :

Last login: Thu Jun 19 23:37:55 2014 from 192.168.0.10 

ls 
[email protected]:~$ ls 
[0m[01;34mbin[0m           Rplots1.pdf 
[01;32mbtsync[0m          Rplots.pdf 
btsync.conf~        [01;31mrstudio-server-0.95.265-amd64.deb[0m 
[01;31mbtsync_glibc23_x64.tar[0m      screen.vba 
[01;34mbudget[0m          [01;34mshiny[0m 
[01;3 
Connection closed. 

사람이 나를 설명 할 수 무엇을 것입니다 에, 그리고 대신 꽤 출력을 얻는 방법? 감사

답변

5

그 디렉토리를 강조하기 위해 ls에 의해 사용되는 터미널 색상 코드입니다, 등 실행 파일은 등 별칭을 호출 피하고 않은 색 출력을 얻기 위해 명시 적으로 (일부 배포판이나, ls --color=never) /bin/ls를 호출 할 수 있습니다.

색상은 [0m[01;34m과 같은 암호 코드를 사용하여 정의됩니다. 여기에 터미널이 ls 색상을 사용하는 경우처럼 보이는 방법은 다음과 같습니다 enter image description here

+0

감사

, 즉 그 것이었다! – user943987

관련 문제