Python Forum

Full Version: BrokenPipeError: [Errno 32] Broken pipe
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
So I've been working on this remote command script for sometime now but my work has been hindered by this pesky error:
BrokenPipeError: [Errno 32] Broken pipe
I'm a new Coder so this is a pretty new experience for me.
client:
#!/usr/bin/env python3
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
Host = input('Remote Host:')
port = 4444
s.connect((Host, port))
while True:
	cmd = input('Host-->Rhost:')
	cmd2 = cmd.encode('utf-8')
	s.sendall(cmd2)
	data = s.recv(1024)
	print(data)
server:
import socket
import platform
import subprocess
import time
s  = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
Host = platform.node()
port = 4444
s.bind((Host, port))
s.listen(1)
conn, addr = s.accept()
while True:
	data = conn.recv(1024)
	data2 = data.decode('utf-8')
	z = subprocess.Popen(data2, shell=True, stdout=subprocess.PIPE,   stderr=subprocess.PIPE)
	
	time.sleep(10)
	z2 = z.stdout.read() + z.stderr.read()
	s.sendall(z2)
It would be really helpful if I could get some help with this.
please show complete unaltered error traceback, it contains very useful information that can be used to find the issue.
(May-04-2021, 09:56 AM)Larz60+ Wrote: [ -> ]please show complete unaltered error traceback, it contains very useful information that can be used to find the issue.

Sure no problem.

Traceback (most recent call last):
  File "/home/kali/Desktop/server.py", line 18, in <module>
    s.sendall(z2)
BrokenPipeError: [Errno 32] Broken pipe
(May-04-2021, 09:56 AM)Larz60+ Wrote: [ -> ]please show complete unaltered error traceback, it contains very useful information that can be used to find the issue.

I Can tell its something with line 18 and above, but I'm not sure How I messed up the piping.
conn.sendall(z2) looks much better to me than s.sendall(z2)
(May-05-2021, 09:23 AM)Gribouillis Wrote: [ -> ]conn.sendall(z2) looks much better to me than s.sendall(z2)

This seemed to fix it thank you sooo Much!