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
  How to include one script into another? MorningWave 8 306 Mar-21-2024, 10:34 PM
Last Post: MorningWave
  ChromeDriver breaking Python script genericusername12414 1 218 Mar-14-2024, 09:39 AM
Last Post: snippsat
  using PowerShell from Python script for mounting shares tester_V 8 402 Mar-12-2024, 06:26 PM
Last Post: tester_V
  No Internet connection when running a Python script basil_555 8 443 Mar-11-2024, 11:02 AM
Last Post: snippsat
Question Running Python script through Task Scheduler? Winfried 8 338 Mar-10-2024, 07:24 PM
Last Post: Winfried
  Combine console script + GUI (tkinter) dejot 2 361 Feb-27-2024, 04:38 PM
Last Post: deanhystad
  How to receive two passed cmdline parameters and access them inside a Python script? pstein 2 278 Feb-17-2024, 12:29 PM
Last Post: deanhystad
  OBS Script Troubleshooting Jotatochips 0 253 Feb-10-2024, 06:18 PM
Last Post: Jotatochips
  Triggering a ps1 script in remote windows server via http python request jasveerjassi 1 321 Jan-26-2024, 07:02 PM
Last Post: deanhystad
  Make entire script run again every 45 mo NDillard 0 293 Jan-23-2024, 09:40 PM
Last Post: NDillard

Forum Jump:

User Panel Messages

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