func (s *Server) handleExec(ch ssh.Channel, req *ssh.Request, ctx *ctx) error {
	execResponse, err := parseExecRequest(req, ctx)
	if err != nil {
		ctx.Infof("failed to parse exec request: %v", err)
		replyError(ch, req, err)
		return trace.Wrap(err)
	}
	if req.WantReply {
		req.Reply(true, nil)
	}
	// a terminal has been previously allocate for this command.
	// run this inside an interactive session
	if ctx.term != nil {
		return s.reg.openSession(ch, req, ctx)
	}
	// ... otherwise, regular execution:
	result, err := execResponse.start(ch)
	if err != nil {
		ctx.Error(err)
		replyError(ch, req, err)
	}
	if result != nil {
		ctx.Debugf("%v result collected: %v", execResponse, result)
		ctx.sendResult(*result)
	}
	if err != nil {
		return trace.Wrap(err)
	}
	// in case if result is nil and no error, this means that program is
	// running in the background
	go func() {
		result, err := execResponse.wait()
		if err != nil {
			ctx.Errorf("%v wait failed: %v", execResponse, err)
		}
		if result != nil {
			ctx.sendResult(*result)
		}
	}()
	return nil
}
// handleExec is responsible for executing 'exec' SSH requests (i.e. executing
// a command after making an SSH connection)
//
// Note: this also handles 'scp' requests because 'scp' is a subset of "exec"
handleExec is responsible for executing 'exec' SSH requests

this also handles 'scp' requests because 'scp' is a subset of "exec"
// handleExec is responsible for executing ' exec ' SSH requests ( i . e . executing // a command after making an SSH connection ) // // Note : this also handles ' scp ' requests because ' scp ' is a subset of " exec "
func (s *Server) handleExec(ch ssh.Channel, req *ssh.Request, ctx *ctx) error {
	execResponse, err := parseExecRequest(req, ctx)
	if err != nil {
		ctx.Infof("failed to parse exec request: %v", err)
		replyError(ch, req, err)
		return trace.Wrap(err)
	}
	if req.WantReply {
		req.Reply(true, nil)
	}
	if ctx.term != nil {
		return s.reg.openSession(ch, req, ctx)
	}
	result, err := execResponse.start(ch)
	if err != nil {
		ctx.Error(err)
		replyError(ch, req, err)
	}
	if result != nil {
		ctx.Debugf("%v result collected: %v", execResponse, result)
		ctx.sendResult(*result)
	}
	if err != nil {
		return trace.Wrap(err)
	}
	go func() {
		result, err := execResponse.wait()
		if err != nil {
			ctx.Errorf("%v wait failed: %v", execResponse, err)
		}
		if result != nil {
			ctx.sendResult(*result)
		}
	}()
	return nil
}
func ( s * Server ) handleExec ( ch ssh . Channel , req * ssh . Request , ctx * ctx ) error { execResponse , err := parseExecRequest ( req , ctx ) if err != nil { ctx . Infof ( " " , err ) replyError ( ch , req , err ) return trace . Wrap ( err ) } if req . WantReply { req . Reply ( true , nil ) } if ctx . term != nil { return s . reg . openSession ( ch , req , ctx ) } result , err := execResponse . start ( ch ) if err != nil { ctx . Error ( err ) replyError ( ch , req , err ) } if result != nil { ctx . Debugf ( " " , execResponse , result ) ctx . sendResult ( * result ) } if err != nil { return trace . Wrap ( err ) } go func ( ) { result , err := execResponse . wait ( ) if err != nil { ctx . Errorf ( " " , execResponse , err ) } if result != nil { ctx . sendResult ( * result ) } } ( ) return nil }
handleExec is responsible for executing 'exec' SSH requests
handleExec is responsible for executing ' exec ' SSH requests
// a terminal has been previously allocate for this command. // run this inside an interactive session // ... otherwise, regular execution: // in case if result is nil and no error, this means that program is // running in the background