run the command and get the output back tryoutput subprocess check_output(command,stderr=subprocess stdoutshell=trueexceptoutput "failed to execute command \ \nsend the output back to the client return output by nowyou're an old hand at creating tcp servers complete with threadingso won' dive in to the server_loop function the run_command functionhowevercontains new library we haven' covered yetthe subprocess library subprocess provides powerful process-creation interface that gives you number of ways to start and interact with client programs in this case we're simply running whatever command we pass inrunning it on the local operating systemand returning the output from the command back to the client that is connected to us the exception-handling code will catch generic errors and return back message letting you know that the command failed now let' implement the logic to do file uploadscommand executionand our shell def client_handler(client_socket)global upload global execute global command check for upload if len(upload_destination)read in all of the bytes and write to our destination file_buffer "keep reading data until none is available while truedata client_socket recv( if not databreak elsefile_buffer +data now we take these bytes and try to write them out tryfile_descriptor open(upload_destination,"wb"file_descriptor write(file_bufferfile_descriptor close(acknowledge that we wrote the file out client_socket send("successfully saved file to % \ \nupload_destinationexceptclient_socket send("failed to save file to % \ \nupload_destinationcheck for command execution if len(execute)run the command output run_command(executeclient_socket send(outputnow we go into another loop if command shell was requested