1

I am fairly new to python so forgive my bad errors or stupid questions. I made a program that can send commands from a remote computer to another computer, everything seems to work but I can't figure out how to capture the output from the client and send to the remote computer. Any help would be appreciated. My code for the remote side :

import time
import sys
import socket
import os
def func():
    command = input(str("cmd or pwsh? : "))
    conn.send(command.encode())
    print("command has been sent, waiting")

s = socket.socket()
host = socket.gethostname()
print(host)
port = 8080
s.bind((host,port))
print("Waiting")
s.listen(1)
conn, addr = s.accept()
print("Connected")

func()
x = 1
while True:
    func()

Code for the client side :

import time
import sys
import socket
import os

def input():
    command = s.recv(1024)
    command = command.decode()
    os.system(command)

s = socket.socket()
host = "192.168.100.3"
port = 8080
s.connect((host, port))
print("Connected to server ")

def input():
    command = s.recv(1024)
    command = command.decode()
    os.system(command)

input()
x = 1
while True:
    input()
robotmr
  • 21
  • 4
  • Does this answer your question? [Running shell command and capturing the output](https://stackoverflow.com/questions/4760215/running-shell-command-and-capturing-the-output) – JonSG Aug 06 '21 at 18:41
  • 2
    `os.system` can't get output - you have to use fucntions from module [subprocess](https://docs.python.org/3/library/subprocess.html) – furas Aug 06 '21 at 19:11
  • Could you give me a sample example I can't understand how to capture an output and send back to the remote side – robotmr Aug 07 '21 at 04:16

0 Answers0