Commit e7aca024 authored by joliu's avatar joliu

物联网操作系统开篇,深层基于shell的命令行终端

parent 0a52556b
import socket
import sys
import numpy as np
import json
def execute(port, message):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("192.168.12.19", port))
s.sendall(message.encode())
response = s.recv(1024).decode()
print(response)
from controler import execute
import sys
if len(sys.argv) != 3:
print("Usage: port database_name")
exit(0)
cmd = "controller&show&%s" % sys.argv[2]
execute(int(sys.argv[1]), cmd)
import subprocess
def Print(msg):
print(msg)
def Input():
print("\033[1;35mopencps $ \033[0m", end='')
return input()
command_list = subprocess.getoutput('cd bin && ls *.py').split('\n')
commands = [x.split('.')[0] for x in command_list if x != 'controler.py']
while True:
cmd = Input()
if cmd in ['quit', 'bye', 'exit']:
Print("bye")
break
if cmd[0] == '%':
c_list = [x for x in cmd[1:].split(' ')]
if c_list[0] == 'cd':
print("not support command")
continue
subprocess.call((c_list))
continue
if not cmd.split(' ')[0] in commands:
Print('Illegal Command!')
continue
else:
c_list = cmd.split(' ')
run_commands = "python3 "
c_list[0] = 'bin/' + c_list[0] + '.py'
c_list = ['python'] + c_list
subprocess.call((c_list))
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment