Click here to Skip to main content
15,905,071 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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,
C#
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);
}


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.
Posted
Updated 23-Mar-16 23:34pm
v2

1 solution

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).
 
Share this answer
 
Comments
nikhil2015 5-Apr-16 7:31am    
public void WriteLineEsc(string cmd)
{
WriteEsc(cmd + "\x1b");
}

public void WriteEsc(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);
}

this worked for me

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900