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
  Running script from remote to server invisiblemind 4 749 Mar-28-2025, 07:57 AM
Last Post: buran
  Insert command line in script lif 4 1,025 Mar-24-2025, 10:30 PM
Last Post: lif
  modifying a script mackconsult 1 593 Mar-17-2025, 04:13 PM
Last Post: snippsat
  help with a script that adds docstrings and type hints to other scripts rickbunk 2 1,262 Feb-24-2025, 05:12 AM
Last Post: from1991
  Detect if another copy of a script is running from within the script gw1500se 4 1,137 Jan-31-2025, 11:30 PM
Last Post: Skaperen
  pass arguments from bat file to pyhon script from application absolut 2 1,129 Jan-13-2025, 11:05 AM
Last Post: DeaD_EyE
  Best way to feed python script of a file absolut 6 1,173 Jan-11-2025, 07:03 AM
Last Post: Gribouillis
  How to make it so whatever I input into a script gets outputted on a different file spermatozwario 4 1,180 Nov-24-2024, 12:58 PM
Last Post: deanhystad
  [SOLVED] [Linux] Run Python script through cron? Winfried 2 1,240 Oct-19-2024, 06:29 PM
Last Post: Winfried
  Help for Tiktok Script Jasson187512 0 764 Oct-09-2024, 08:42 AM
Last Post: Jasson187512

Forum Jump:

User Panel Messages

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