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
  run part of a script with a different version of Python jdog 3 622 May-27-2024, 01:57 AM
Last Post: Alice12
Shocked Script get's really weird error DaJohn 7 320 May-26-2024, 09:10 AM
Last Post: snippsat
Music Python Script Repeating Number When Saving Facebook Photos ThuanyPK 2 219 May-13-2024, 10:59 PM
Last Post: ebn852_pan
  Trying to generating multiple json files using python script dzgn989 4 325 May-10-2024, 03:09 PM
Last Post: deanhystad
  Problems passing arguments containing spaces to bash script and then on to python kaustin 6 607 Apr-03-2024, 08:26 PM
Last Post: deanhystad
  Using a script to open multiple shells? SuchUmami 9 748 Apr-01-2024, 10:04 AM
Last Post: Gribouillis
  How to include one script into another? MorningWave 8 677 Mar-21-2024, 10:34 PM
Last Post: MorningWave
  ChromeDriver breaking Python script genericusername12414 1 417 Mar-14-2024, 09:39 AM
Last Post: snippsat
  using PowerShell from Python script for mounting shares tester_V 8 697 Mar-12-2024, 06:26 PM
Last Post: tester_V
  No Internet connection when running a Python script basil_555 8 856 Mar-11-2024, 11:02 AM
Last Post: snippsat

Forum Jump:

User Panel Messages

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