By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,899 Members | 1,230 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,899 IT Pros & Developers. It's quick & easy.

How to run console application on telnet window ?

P: 2
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 .

Expand|Select|Wrap|Line Numbers
  1. namespace ConsoleApplication2
  2. {
  3.     class Program
  4.     {
  5.         string path = @"text file path";
  6.  
  7.         SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["constring"].ToString());
  8.  
  9.         public void getConsoleInput()
  10.         {
  11.             try
  12.             {
  13.                 FileInfo fi = new FileInfo(path);
  14.  
  15.                 for (int i = 0; i <= 0; i++)
  16.                 {
  17.                     Console.WriteLine("");
  18.                     using (StreamWriter sw = new StreamWriter(path))
  19.                     {
  20.                         sw.WriteLine(Console.ReadLine());
  21.                         sw.Close();
  22.                     }
  23.                 }
  24.             }
  25.             catch (Exception e)
  26.             {
  27.                 Console.WriteLine(e.Message);
  28.             }
  29.         }
  30.  
  31.         public void ReadWriteIntoFile()
  32.         {
  33.             try
  34.             {
  35.                 string filename = @"txt file path";
  36.                 StringBuilder sb = new StringBuilder();
  37.  
  38.                 StreamReader sr = new StreamReader(path);
  39.                 string s = sr.ReadLine();
  40.                 sr.Close();
  41.  
  42.                 DataExport("Select * from PATIENT_TABLE where [BARCODE] = '" + s + "'", filename);
  43.             }
  44.             catch { }
  45.         }
  46.  
  47.         public void DataExport(string SelectQuery, string filename)
  48.         {
  49.             try
  50.             {
  51.                 using (var dt = new DataTable())
  52.                 {
  53.                     using (var da = new SqlDataAdapter(SelectQuery, con))
  54.                     {
  55.                         da.Fill(dt);
  56.                         var rows =
  57.                             from dr in dt.Rows.Cast<datarow>()
  58.                             select String.Join(
  59.                                 ",",
  60.                                 from dc in dt.Columns.Cast<datacolumn>()
  61.                                 let t1 = Convert.IsDBNull(dr[dc]) ? "" : dr[dc].ToString()
  62.                                 let t2 = t1.Contains(",") ? String.Format("\"{0}\"", t1) : t1
  63.                                 select t2);
  64.  
  65.                         using (var sw = new StreamWriter(filename))
  66.                         {
  67.                             // sw.WriteLine(header);
  68.                             foreach (var row in rows)
  69.                             {
  70.                                 sw.WriteLine(row);
  71.                             }
  72.                             sw.Close();
  73.                         }
  74.                     }
  75.                 }
  76.             }
  77.             catch (Exception e) { Console.WriteLine(e.Message); }
  78.         }
  79.  
  80.         public void WriteFileOutput()
  81.         {
  82.             string path = @"C:\Users\Priya\Desktop\Project\Data.txt";
  83.             if (File.Exists(path))
  84.             {
  85.                 string[] lines = File.ReadAllLines(path);
  86.  
  87.                 foreach (string line in lines)
  88.                 {
  89.                     Console.WriteLine(line);
  90.                 }
  91.  
  92.             }
  93.             Console.ReadLine();
  94.         }
  95.  
  96.         public static void Main(string[] args)
  97.         {
  98.             Program p = new Program();
  99.             p.getConsoleInput();
  100.             p.ReadWriteIntoFile();
  101.             p.WriteFileOutput();
  102.         }
  103.  
  104.         public void timerfor()
  105.         {
  106.             Timer t;
  107.             t = new System.Timers.Timer(10000);
  108.             // Hook up the Elapsed event for the timer. 
  109.             t.Elapsed += OnTimedEvent;
  110.             t.Enabled = true;
  111.         }
  112.  
  113.         private static void OnTimedEvent(Object source, ElapsedEventArgs e)
  114.         {
  115.             Console.WriteLine(ConsoleKey.Enter);          
  116.         }
  117.     }
  118. }
  119.  
  120.  
May 18 '15 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.