如何在telnet窗口上运行控制台应用程序? [英] How to run console application on telnet window ?

查看:171
本文介绍了如何在telnet窗口上运行控制台应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了1个控制台应用程序,它运行得很好。在我的项目中,我必须从输入字符串和telnet特定窗口命名为telnet 192.168.xx并运行我的项目并提供与该字符串相关的输出(即条形码代码是我必须在telnet窗口上接收并提供输出(与同一telnet窗口中的代码相关的条形码代码的详细信息)。我可以在cmd.exe和ConsoleApplication.exe中运行此控制台应用程序,但现在我手动传递条形码字符串然后如何在telnet窗口上运行此应用程序并自动接收条形码字符串?请帮忙。



预付结转



这是我的完整代码



I have created 1 console Application and it is running perfectly. In my project I have to take input string and from telnet specific window named as "telnet 192.168.x.x" and run my project and give output related to that string (i.e barcode code is all I have to receive on telnet window and give output (details of barcode code) related to that code in same telnet window). I am able to run this console app in cmd.exe and ConsoleApplication.exe but now I am passing barcode string manually then how to run this application on telnet window and receive barcode string automatically? please help .

Thanks in Advance

here is my full code

namespace ConsoleApplication2
{
    class Program
    {
        string path = @"text file path";

        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["constring"].ToString());

        public void getConsoleInput()
        {
            try
            {
                FileInfo fi = new FileInfo(path);

                for (int i = 0; i <= 0; i++)
                {
                    Console.WriteLine("");
                    using (StreamWriter sw = new StreamWriter(path))
                    {
                        sw.WriteLine(Console.ReadLine());
                        sw.Close();
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }

        public void ReadWriteIntoFile()
        {
            try
            {
                string filename = @"txt file path";
                StringBuilder sb = new StringBuilder();

                StreamReader sr = new StreamReader(path);
                string s = sr.ReadLine();
                sr.Close();

                DataExport("Select * from PATIENT_TABLE where [BARCODE] = '" + s + "'", filename);
            }
            catch { }
        }

        public void DataExport(string SelectQuery, string filename)
        {
            try
            {
                using (var dt = new DataTable())
                {
                    using (var da = new SqlDataAdapter(SelectQuery, con))
                    {
                        da.Fill(dt);
                        var rows =
                            from dr in dt.Rows.Cast<datarow>()
                            select String.Join(
                                ",",
                                from dc in dt.Columns.Cast<datacolumn>()
                                let t1 = Convert.IsDBNull(dr[dc]) ? "" : dr[dc].ToString()
                                let t2 = t1.Contains(",") ? String.Format("\"{0}\"", t1) : t1
                                select t2);

                        using (var sw = new StreamWriter(filename))
                        {
                            // sw.WriteLine(header);
                            foreach (var row in rows)
                            {
                                sw.WriteLine(row);
                            }
                            sw.Close();
                        }
                    }
                }
            }
            catch (Exception e) { Console.WriteLine(e.Message); }
        }

        public void WriteFileOutput()
        {
            string path = @"text file path";
            if (File.Exists(path))
            {
                string[] lines = File.ReadAllLines(path);

                foreach (string line in lines)
                {
                    Console.WriteLine(line);
                }

            }
            Console.ReadLine();
        }

        public static void Main(string[] args)
        {
            Program p = new Program();
            p.getConsoleInput();
            p.ReadWriteIntoFile();
            p.WriteFileOutput();
        }

        public void timerfor()
        {
            Timer t;
            t = new System.Timers.Timer(10000);
            // Hook up the Elapsed event for the timer. 
            t.Elapsed += OnTimedEvent;
            t.Enabled = true;
        }

        private static void OnTimedEvent(Object source, ElapsedEventArgs e)
        {
            Console.WriteLine(ConsoleKey.Enter);          
        }
    }
}
<pre lang="c#">

推荐答案

哇,阅读你的问题确实是一个难题。让我为你改一下。您有一些从Telnet(条形码编号)收到的数据,您希望外部控制台应用程序使用它,根据这些数据,您将检索一些数据库信息,并希望在telnet中显示相同的数据。那么你现在拥有的是控制台应用程序,通过手动提供此条形码并获得预期输出,但您希望将其与telnet集成,可以正常工作。是吗????



假设我的理解是对的,你必须做到以下几点。



1.您不必尝试从telnet窗口读取数据,而是必须创建一个TcpClient并在您认为是条形码阅读器的情况下收听Telnet服务器。有很多可用的示例如何使用C#

创建一个简单的Telnet客户端2.执行您需要执行的操作并在控制台窗口中显示结果。
Wow, it is really a puzzle to read your question. Let me rephrase it for you. You have some data that you receive from Telnet (Barcode number) which you want to use it by your external console application and based on this data you will retrieve some DB info and you want the same to be shown back in the telnet. Well what you have now is the console app which works fine by manually providing this barcode and getting the expected output but you want to integrate this with the telnet. Is that right ????

Assuming my understanding is right, You have to do the following.

1. Rather than trying to read the data from a telnet window, you have to create a TcpClient and listen to the Telnet server in your case I assume its the barcode reader. There are plenty of examples available how to create a simple Telnet client using C#
2. Perform the operations that you need to perform and show the results in your console window itself.


这篇关于如何在telnet窗口上运行控制台应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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