使用C#自动化telnet - 使用简约库 [英] Automate telnet using C#- using minimalistic library

查看:82
本文介绍了使用C#自动化telnet - 使用简约库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在使用Minimalistic Library进行Telnet Automation.I刚刚通过硬编码传递输入值,它正在工作。在这种情况下闪烁的游标在控制台上的字符串结尾像字符串| - >闪烁光标



以下代码用于提供输入值并按自动输入键,

Hi,

I am Using Minimalistic Library for Telnet Automation.I Just Passed the input values via hard coding and it is working.In this case the blinking cursor on console is at the end of a string like string | -->Blinking Cursor

The below code is using to give input values and press enter Key Automatically,

s += Read();
if (!s.Contains("string"))
   throw new Exception("Failed to get the string");
WriteLine("");//passing empty value to press enter key Automatically

public void WriteLine(string cmd)
{
    Write(cmd + "\n");
}

public void Write(string cmd)
{
    if (!tcpSocket.Connected) return;
    byte[] buf = System.Text.ASCIIEncoding.ASCII.GetBytes(cmd.Replace("\0xFF","\0xFF\0xFF"));
    tcpSocket.GetStream().Write(buf, 0, buf.Length);
}





但在某些情况下,闪烁的光标指向字符串之前的'|'字符串'在控制台上。 | - >闪烁光标



在这种情况下,我无法自动按回车键。



有人可以帮我这个吗?



我尝试过:



编辑了minimalistic库并尝试过。



But in some cases the blinking cursor is pointed before the string like '| string' on console. |-->Blinking Cursor

In this case i am not able to press enter key Automatically.

Can someone please help me on this?

What I have tried:

edited minimalistic library and tried.

推荐答案

根据控制台类型,您可以通过发送相应的控制序列(或在命令前面添加命令)来删除该行)。请参阅 console_codes(4) - Linux手册页 [ ^ ]用于Linux控制台控制代码。



但你应该检查光标在那个位置的原因以及是否可以接受删除线(没有不必要的副作用)。
Depending on the console type you may erase the line by sending the corresponding control sequence (or prefixing you command with it). See console_codes(4) - Linux manual page[^] for Linux console control codes.

But you should check why the cursor is at that position and if erasing the line can be accepted (does not have unwanted side effects).


这篇关于使用C#自动化telnet - 使用简约库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆