Skip to content

Instantly share code, notes, and snippets.

@tacahiroy
Created May 17, 2017 04:27
Show Gist options
  • Select an option

  • Save tacahiroy/1b2584ab962465fcdeb34adeb2e15871 to your computer and use it in GitHub Desktop.

Select an option

Save tacahiroy/1b2584ab962465fcdeb34adeb2e15871 to your computer and use it in GitHub Desktop.
Runs a command in a fake tty and gets output
#!/usr/bin/env python3
import os,sys,time
os.environ['TERM'] = 'xterm'
pid,fd = os.forkpty()
if pid == 0:
os.execv('/sbin/esxtop', [])
sys.exit(0)
else:
out = os.read(fd,300)
print(out)
os.write(fd,'/sbin/esxtop\n')
time.sleep(1)
out = os.read(fd,300)
print(out)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment