Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
Notice removed Authoritative reference needed by CommunityBot
Bounty Ended with Kentzo's answer chosen by CommunityBot
Notice added Authoritative reference needed by Ishan Khare
Bounty Started worth 50 reputation by Ishan Khare
added output
Source Link
Ishan Khare
  • 1.8k
  • 4
  • 31
  • 63

I'm trying to create an execution environment/shell that will remotely execute on a server, which streams the stdout,err,in over the socket to be rendered in a browser. I currently have tried the approach of using subprocess.run with a PIPE. The Problem is that I get the stdout after the process has completed. What i want to achieve is to get a line-by-line, pseudo-terminal sort of implementation.

My current implementation

test.py

def greeter(): for _ in range(10): print('hello world') greeter() 

and in the shell

>>> import subprocess >>> result = subprocess.run(['python3', 'test.py'], stdout=subprocess.PIPE) >>> print(result.stdout.decode('utf-8')) hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world 

If i try to attempt even this simple implementation with pty, how does one do it?

I'm trying to create an execution environment/shell that will remotely execute on a server, which streams the stdout,err,in over the socket to be rendered in a browser. I currently have tried the approach of using subprocess.run with a PIPE. The Problem is that I get the stdout after the process has completed. What i want to achieve is to get a line-by-line, pseudo-terminal sort of implementation.

My current implementation

test.py

def greeter(): for _ in range(10): print('hello world') greeter() 

and in the shell

>>> import subprocess >>> result = subprocess.run(['python3', 'test.py'], stdout=subprocess.PIPE) >>> print(result.stdout.decode('utf-8')) 

If i try to attempt even this simple implementation with pty, how does one do it?

I'm trying to create an execution environment/shell that will remotely execute on a server, which streams the stdout,err,in over the socket to be rendered in a browser. I currently have tried the approach of using subprocess.run with a PIPE. The Problem is that I get the stdout after the process has completed. What i want to achieve is to get a line-by-line, pseudo-terminal sort of implementation.

My current implementation

test.py

def greeter(): for _ in range(10): print('hello world') greeter() 

and in the shell

>>> import subprocess >>> result = subprocess.run(['python3', 'test.py'], stdout=subprocess.PIPE) >>> print(result.stdout.decode('utf-8')) hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world 

If i try to attempt even this simple implementation with pty, how does one do it?

Source Link
Ishan Khare
  • 1.8k
  • 4
  • 31
  • 63

Use python's pty to create a live console

I'm trying to create an execution environment/shell that will remotely execute on a server, which streams the stdout,err,in over the socket to be rendered in a browser. I currently have tried the approach of using subprocess.run with a PIPE. The Problem is that I get the stdout after the process has completed. What i want to achieve is to get a line-by-line, pseudo-terminal sort of implementation.

My current implementation

test.py

def greeter(): for _ in range(10): print('hello world') greeter() 

and in the shell

>>> import subprocess >>> result = subprocess.run(['python3', 'test.py'], stdout=subprocess.PIPE) >>> print(result.stdout.decode('utf-8')) 

If i try to attempt even this simple implementation with pty, how does one do it?