Python Forum
Real-Time output of server script on a client script.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Real-Time output of server script on a client script.
#1
So i want to get a real-time readout of commands executed on the server side of the two scripts, How would I do that without only limited output?
Server side:
#!/usr/bin/env python3

import socket
import platform
import subprocess
import shlex
s  = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
Host = platform.node()
port = 4444
if  True:
	try:
		s.bind((Host, port))
		s.listen(1)
	except OSError:
		print('The script is already running.')
		s.close()
		exit()
conn, addr = s.accept()
while True:
    data = conn.recv(4096)
    data2 = data.decode('utf-8')
    z = subprocess.run(data2, shell=True, stdout=subprocess.PIPE,	stderr=subprocess.PIPE, capture_output=True)
    z2 = z.stdout + z.stderr
    try:
    	conn.sendall(z2)
    except BrokenPipeError:
    	print('the connection was closed.')
Client side:

#!/usr/bin/env python3

import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
if True:
	try:
		Host = input('Remote Host:')
		port = 4444
		s.connect((Host, port))
	except ConnectionRefusedError:
		print('connection refused.')
		s.close()
		exit()
	except socket.gaierror:
		print('connection refused.')
		s.close()
		exit()
while True:
    cmd = input('Host-->(Remote)Host:')
    cmd2 = cmd.encode('utf-8')
    try:
    	s.sendall(cmd2)
    	data = s.recv(4096)
    	data2 = data.decode('utf-8')
    	print(data2)
    except BrokenPipeError:
    	print('The connection has been closed by the Host.')
Reply
#2
I really need some help with this, as ive been working on it for a while now, and I want to move onto new projects.
Reply
#3
Perhaps it would help if you told us what the output is and what output you expected.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Need a script to replace an existing Python installation in a version-independent dir pstein 7 146 May-09-2026, 01:04 PM
Last Post: DeaD_EyE
  Merge Script Functionality in a Single Script gksharma 8 183 Feb-04-2026, 11:47 PM
Last Post: deanhystad
  Py script to APP on MAC tester_V 3 775 Dec-05-2025, 08:12 PM
Last Post: tester_V
  Trying to install the edk2-rk3399 code but the script fails due some python bug mariozio 2 1,919 Aug-17-2025, 10:25 PM
Last Post: mariozio
  Running script from remote to server invisiblemind 4 1,837 Mar-28-2025, 07:57 AM
Last Post: buran
  Insert command line in script lif 4 2,200 Mar-24-2025, 10:30 PM
Last Post: lif
  modifying a script mackconsult 1 1,128 Mar-17-2025, 04:13 PM
Last Post: snippsat
  help with a script that adds docstrings and type hints to other scripts rickbunk 1 1,894 Feb-24-2025, 05:12 AM
Last Post: from1991
  Detect if another copy of a script is running from within the script gw1500se 4 2,111 Jan-31-2025, 11:30 PM
Last Post: Skaperen
  pass arguments from bat file to pyhon script from application absolut 2 2,880 Jan-13-2025, 11:05 AM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020