-
-
Save tareksander/749ab81186ebb7b62aa95007d1c1b6d2 to your computer and use it in GitHub Desktop.
Quick proof-of-concept reimplementation of am for Termux over a socket
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/data/data/com.termux/files/usr/bin/env python3 | |
import sys | |
from socket import socket, AF_UNIX, SOCK_STREAM, timeout, SOL_SOCKET, SO_PEERCRED, SHUT_WR | |
c = socket(AF_UNIX, SOCK_STREAM) | |
c.connect("/data/data/com.termux/files/am-socket") | |
c.shutdown(SHUT_WR) | |
for i in sys.argv[1:]: | |
c.sendall(bytes('"'+i+'" ',"utf-8")) | |
c.sendall(bytes("\0", "utf-8")) | |
buff = b'' | |
b = b'' | |
ret = 0 | |
try: | |
while True: | |
b = c.recv(4096) | |
buff += b | |
if len(b) == 0: | |
break | |
except ConnectionResetError: | |
pass | |
except BrokenPipeError: | |
pass | |
retstr = str(buff, "utf-8") | |
l = retstr.split("\0") | |
retval = int(l[0]) | |
out = l[1] | |
err = l[2] | |
print(out, end='', flush=True) | |
print(err, end='', flush=True, file=sys.stderr) | |
sys.exit(retval) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment