调用(.exe)控制台应用程序时,命令提示符不会打开 [英] command prompt do not opens up when calling (.exe) console application
本文介绍了调用(.exe)控制台应用程序时,命令提示符不会打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家都知道我正在开发从comport读取的程序数据并保存输入.txt文件,但是我希望命令提示符在调用(.exe)控制台应用程序时不打开请帮助我,我的代码是
hi to all know i was develop my program data read from comport and save out put in .txt file but i want command prompt do not opens up when calling (.exe) console application pls help me my code are
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO.Ports;
using System.IO;
using System.Runtime.InteropServices;
namespace PortDataReceived
{
class Program
{
static void Main(string[] args)
{
SerialPort mySerialPort = new SerialPort("COM1");
if (mySerialPort.IsOpen == true) mySerialPort.Close();
mySerialPort.BaudRate = 2400;
mySerialPort.Parity = Parity.None;
mySerialPort.StopBits = StopBits.One;
mySerialPort.DataBits = 8;
mySerialPort.Handshake = Handshake.None;
mySerialPort.Open();
// Console.WriteLine("Press any key to continue...");
Console.ReadLine();
mySerialPort.ReadTimeout = 100;
string indata = mySerialPort.ReadExisting();
Console.WriteLine(indata);
if (string.IsNullOrEmpty(indata))
{
StringBuilder builder = new StringBuilder();
StreamWriter sw = new StreamWriter(@"c:\arjun.txt", true);
sw.WriteLine(indata);
sw.Close();
}
else
{
StringBuilder builder = new StringBuilder();
for (int i = 0; i < indata.Length-8; i += 8)
{
string section = indata.Substring(i, 8);
//int ascii = 0;
string ascii = "";
try
{
//ascii = Convert.ToInt32(section, 2);
ascii = section;
StreamWriter sw = new StreamWriter(@"c:\arjun.txt", true);
foreach (char c in section)
{
if (Char.IsLetterOrDigit(c))
{
builder.Append(c);
}
}
sw.WriteLine(builder.ToString());
sw.Close();
break;
}
catch(Exception e)
{
throw e;
}
// builder.Append((char)ascii);
}
// Console.WriteLine(builder.ToString());
// Console.WriteLine(indata);
//Console.WriteLine("Data Received:");
//Console.Write(indata);
// Console.ReadKey();
mySerialPort.Close();
}
}
}
}
推荐答案
看看这里:
http://stackoverflow.com/questions/3497652/making-my-console-application-invisible [ ^ ]
http://stackoverflow.com/questions/2763669/how-to- hide-a-console-application-in-c-sharp [ ^ ]
http://cs.hubfs.net/topic/None/59579 [ ^ ]
http://amitpatriwala.wordpress.com/2008/04/14/hide-console-application/ [ ^ ]
Hi,
Have a look here:
http://stackoverflow.com/questions/3497652/making-my-console-application-invisible[^]
http://stackoverflow.com/questions/2763669/how-to-hide-a-console-application-in-c-sharp[^]
http://cs.hubfs.net/topic/None/59579[^]
http://amitpatriwala.wordpress.com/2008/04/14/hide-console-application/[^]
这篇关于调用(.exe)控制台应用程序时,命令提示符不会打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文