zoukankan      html  css  js  c++  java
  • python shell

    服务端:

     1 import socket
     2 def connect():
     3     s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     4     s.bind(('192.168.1.105', 8000))
     5     s.listen(1)
     6     print 'Listen on: 8000'
     7     conn, addr = s.accept()
     8     print 'Conn from ', addr
     9 
    10     while True:
    11         cmd = raw_input('cmd>')
    12         if 'exit' in cmd:
    13             conn.send('exit')
    14             conn.close()
    15             break
    16         else:
    17             conn.send(cmd)
    18             print conn.recv(1024)
    19 
    20 connect()

    客户端:

     1 import socket,subprocess
     2 c = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     3 c.connect(('192.168.1.105',8000))
     4 while True:
     5     cmd = c.recv(1024)
     6     if 'exit' in cmd:
     7         c.close()
     8         break
     9     else:
    10         cmd_ = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
    11         c.send(cmd_.stdout.read())
    12         c.send(cmd_.stderr.read())
  • 相关阅读:
    gdb php
    redis启动过程
    php protobuf 安装使用2
    php protobuf 安装使用
    服务治理
    base64编码
    redis-quicklist
    redis-ziplist
    redis-zset数据结构探索
    su root 出现 su: Authentication failure
  • 原文地址:https://www.cnblogs.com/perl6/p/6754996.html
Copyright © 2011-2022 走看看