Added summary block + filename, match count, and line number in output

This commit is contained in:
jouya committed 2026-09-10 18:19:40 -05:00
1 parent fdb0532e44
commit a022c3cba5
2 files changed
+42 -10

No files matched your search

+14 -3
View File
@@ -11,16 +11,27 @@ server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.bind((HOST, PORT))
server_socket.listen()
# print(f"Server listening on {HOST}:{PORT}")
print(f"Server listening on {HOST}:{PORT}")
while True:
conn, addr = server_socket.accept()
# print(f"Connected by {addr}")
print(f"Connected by {addr}")
command = conn.recv(65536)
# print("Received Grep Command:", command.decode())
result = subprocess.run(shlex.split(command.decode()), capture_output=True, text=True)
command_args = shlex.split(command.decode())
if not command_args or command_args[0] != "grep":
response = "Invalid command. Please use the 'grep' command."
conn.sendall(response.encode())
conn.close()
continue
command_args.insert(1, "-n")
result = subprocess.run(command_args, capture_output=True, text=True)
conn.sendall(result.stdout.encode())
conn.close()