0 votes
by (270 points)

Hello,
I want to run to hanlde user's action the following way:

  1. Create a new tab
  2. Add terminalcontrol
  3. Connect by SSH to remote host
  4. Run several commands (user must see them)

this.SetDataProcessingMode(DataProcessingMode.None);
this.Scripting.Send(cmd);
this.SetDataProcessingMode(DataProcessingMode.Automatic);

How to do it properly? If I try to run the command after creation, I get the following exception "Unable to stop background data processing.

1 Answer

0 votes
by (70.4k points)

You can do it like this:

// establish SSH connection
var ssh = new Ssh();
ssh.Connect("ssh.server.com");
ssh.Login("user", "password");

// at first disable user input and unset automatic processing
terminal.UserInputEnabled = false;
terminal.SetDataProcessingMode(DataProcessingMode.None);

// bind terminal control to SSH connection
terminal.Bind(ssh);

// set prompt
terminal.Scripting.Prompt = "regex:[@].*[$] ?";

// send command
terminal.Scripting.Send("echo abc\n");

// wait one second so the user can see it
await Task.Delay(1000);

// wait for prompt
terminal.Scripting.WaitFor(ScriptEvent.Prompt);

// send another command
terminal.Scripting.Send("echo xyz\n");

// again, wait one second so the user can see it
await Task.Delay(1000);

// process the last command by automatic processing and re-enable user input
terminal.SetDataProcessingMode(DataProcessingMode.Automatic);
terminal.UserInputEnabled = true;

Please note that SetDataProcessingMode(DataProcessingMode.None); is called before binding the terminal control to an SSH connection (before the terminal.Bind(ssh) call).

...