using shlex on the client

This commit is contained in:
Aryan Singh committed 2026-09-13 16:06:07 -05:00
1 parent e1fbb3b33e
commit fd11784744
2 files changed
+23 -24

No files matched your search

+18 -19
View File
@@ -44,25 +44,24 @@ while True:
conn, addr = server_socket.accept()
print(f"Connected by {addr}")
command = receive_message(conn)
if command is None:
try:
command = receive_message(conn)
if command is None:
conn.close()
continue
command_args = shlex.split(command)
command_args.insert(1, "-n")
result = subprocess.run(command_args, cwd=SCRIPT_DIR, capture_output=True, text=True)
send_message(conn, result.stdout + result.stderr)
except Exception as e:
error_message = f"Error executing command: {e}"
send_message(conn, error_message)
finally:
conn.close()
continue
command_args = shlex.split(command)
if not command_args or command_args[0] != "grep":
response = "Invalid command. Please use the 'grep' command."
send_message(conn, response)
conn.close()
continue
command_args.insert(1, "-n")
result = subprocess.run(command_args, cwd=SCRIPT_DIR, capture_output=True, text=True)
send_message(conn, result.stdout + result.stderr)
conn.close()
server_socket.close()