anchor.diff:              {direct,F} ->
                   %% Exec called and a Fun or MFA is defined to use.  The F returns the
                   %% value to return.
  -                exec_direct(ConnectionHandler, F, Cmd);
  +                %% The standard I/O is directed from/to the channel ChannelId.
  +                exec_direct(ConnectionHandler, ChannelId, Cmd, F, WantReply, S0);
   
               undefined when S0#state.shell == ?DEFAULT_SHELL ->
                   %% Exec called and the shell is the default shell (= Erlang shell).
                   %% To be exact, eval the term as an Erlang term (but not using the
                   %% ?DEFAULT_SHELL directly). This disables banner, prompts and such.
  -                exec_in_erlang_default_shell(Cmd);
  +                %% The standard I/O is directed from/to the channel ChannelId.
  +                exec_in_erlang_default_shell(ConnectionHandler, ChannelId, Cmd, WantReply, S0);
   
               undefined ->
                   %% Exec called, but the a shell other than the default shell is defined.
  
positive.code:                 buf = empty_buf()}.
  
  %%--------------------------------------------------------------------
  exec_in_erlang_default_shell(Cmd) ->
      case eval(parse(scan(Cmd))) of
  	{ok, Term} ->
              {io_lib:format("~p\n", [Term]), 0, 0};
          {error, Error} when is_atom(Error) ->
              {io_lib:format("Error in ~p: ~p\n", [Cmd,Error]), -1, 1};
          _ ->
              {io_lib:format("Error: ~p\n", [Cmd]), -1, 1}
      end.
  
  scan(Cmd) ->
      erl_scan:string(Cmd). 
  
  parse({ok, Tokens, _}) ->
      erl_parse:parse_exprs(Tokens);
  parse(Error) ->
      Error.
  
  eval({ok, Expr_list}) ->
      case (catch erl_eval:exprs(Expr_list,
                                erl_eval:new_bindings())) of
          {value, Value, _NewBindings} ->
              {ok, Value};
          {'EXIT', {Error, _}} -> 
              {error, Error};
          {error, Error} -> 
              {error, Error};
          Error -> 
              {error, Error}
      end;
  eval({error,Error}) ->
      {error, Error};
  eval(Error) ->
      {error, Error}.
  
  %%--------------------------------------------------------------------
  exec_direct(ConnectionHandler, ExecSpec, Cmd) ->
      try
          case ExecSpec of
              _ when is_function(ExecSpec, 1) ->
                  ExecSpec(Cmd);
              _ when is_function(ExecSpec, 2) ->
                  [{user,User}] = ssh_connection_handler:connection_info(ConnectionHandler, [user]),
                  ExecSpec(Cmd, User);
              _ when is_function(ExecSpec, 3) ->
                  ConnectionInfo =
                      ssh_connection_handler:connection_info(ConnectionHandler, [peer, user]),
                  User = proplists:get_value(user, ConnectionInfo),
                  {_, PeerAddr} = proplists:get_value(peer, ConnectionInfo),
                  ExecSpec(Cmd, User, PeerAddr)
          end
      of
          Reply ->
              return_direct_exec_reply(Reply, Cmd)
      catch
          C:Error ->
              {io_lib:format("Error in \"~s\": ~p ~p~n", [Cmd,C,Error]), -1, 1}
      end.
  
  
  
  return_direct_exec_reply(Reply, Cmd) ->
      case fmt_exec_repl(Reply) of
          {ok,S} ->
              {S, 0, 0};
          {error,S} ->
              {io_lib:format("Error in \"~s\": ~s~n", [Cmd,S]), -1, 1}
      end.
  
  fmt_exec_repl({T,A}) when T==ok ; T==error ->
      try
          {T, io_lib:format("~s",[A])}
      catch
          error:badarg ->
              {T, io_lib:format("~p", [A])};
          C:Err ->
              {error, io_lib:format("~p:~p~n",[C,Err])}
      end;
  fmt_exec_repl(Other) ->
      {error, io_lib:format("Bad exec-plugin return: ~p",[Other])}.
  
  %%--------------------------------------------------------------------
  % Pty can be undefined if the client never sets any pty options before
  
negative.code:     write_chars(ConnectionHandler, ChannelId, Chars),
      {ok, State#state{buf = NewBuf}};
  
  handle_msg({'EXIT', Group, _Reason}, #state{group = Group,
  					    cm = ConnectionHandler,
  					    channel = ChannelId} = State) ->
      ssh_connection:send_eof(ConnectionHandler, ChannelId),
      {stop, ChannelId, State};
  
  