解决方案 »

  1.   


    正常情况下在dos运行应该是上面这个界面,输入“secureDataTool.exe USB0::2391::6056::US12345678::INSTR service snumber US12345678 mnumber MSOX3000A”后dos会输出一些内容,然后提示“Enter the serial numberr again to continue”,接着再次输入US12345678。现在情况是我做了个winform来做这个secureDataTool.exe的外壳,程序运行后只显示到这里我的后台代码如下,麻烦高手指点迷津,感激不尽啊,谢谢!
    namespace secureDataToolGUI
    {
        public partial class Form1 : Form
        {        Process p;
            StreamWriter input;        public Form1()
            {
                InitializeComponent();            p = new Process();
                p.StartInfo.FileName = "cmd.exe";
                p.StartInfo.UseShellExecute = false;
                p.StartInfo.CreateNoWindow = true;
                p.StartInfo.RedirectStandardInput = true;
                p.StartInfo.RedirectStandardOutput = true;            p.OutputDataReceived += new DataReceivedEventHandler(p_OutputDataReceived);            p.Start();
                input = p.StandardInput;
                p.BeginOutputReadLine();
            }        void p_OutputDataReceived(object sender, DataReceivedEventArgs e)
            {
                update(e.Data + Environment.NewLine);
            }        private void button1_Click(object sender, EventArgs e)
            {
                input.WriteLine(textBox1.Text);
                if (textBox1.Text.Contains("\\"))
                {
                    textBox1.Text = "secureDataTool.exe " + label1.Text + textBox3.Text + label2.Text + textBox4.Text + label3.Text + textBox5.Text + label4.Text + textBox6.Text + label5.Text + textBox7.Text;
                    button1.Text = "RUN";
                }
                else
                {
                    textBox1.Text = "";
                    button1.Text = "Load Program";
                }         
            }        //申明delegate更新数据
            delegate void updateDelegate(string msg);
            void update(string msg)
            {
                if (this.InvokeRequired)
                    Invoke(new updateDelegate(update), new object[] { msg });
                else
                {
                    textBox2.Text += msg;
                    textBox2.SelectionStart = textBox2.Text.Length - 1;
                    textBox2.ScrollToCaret();
                }
            }
            //关闭GUI窗口
            private void Form1_FormClosed(object sender, FormClosedEventArgs e)
            {
                p.Close();
            }
            //打开文件浏览对话框
            private void button2_Click(object sender, EventArgs e)
            {
                this.openFileDialog1.ShowDialog();
            }
            //获取文件路径,将路径定位到文件所在位置
            private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
            {
                string filepath = openFileDialog1.FileName;
                int fileposition = filepath.LastIndexOf("\\");
                textBox1.Text = "cd " + filepath.Substring(0, fileposition);
            }
            #region
            //private void textBox3_KeyPress(object sender, KeyPressEventArgs e)
            //{
            //    if (!Char.IsNumber(e.KeyChar) && Convert.ToInt32(e.KeyChar) != 8)
            //    {
            //        e.Handled = true;
            //    }
            //}        //private void textBox4_KeyPress(object sender, KeyPressEventArgs e)
            //{
            //    if (!Char.IsNumber(e.KeyChar) && Convert.ToInt32(e.KeyChar) != 8)
            //    {
            //        e.Handled = true;
            //    }
            //}        //private void textBox5_Leave(object sender, EventArgs e)
            //{
            //    System.Text.RegularExpressions.Regex myregex = new System.Text.RegularExpressions.Regex("[A-Z]{2}[0-9]{8}");
            //    if (!myregex.IsMatch(textBox5.Text))
            //    {
            //        MessageBox.Show("输入格式有误!");
            //        textBox5.Text = "";
            //    }
            //}        //private void textBox6_Leave(object sender, EventArgs e)
            //{
            //    System.Text.RegularExpressions.Regex myregex = new System.Text.RegularExpressions.Regex("[A-Z]{2}[0-9]{8}");
            //    if (!myregex.IsMatch(textBox6.Text))
            //    {
            //        MessageBox.Show("输入格式有误!");
            //        textBox6.Text = "";
            //    }
            //}
            #endregion
        }
    }
      

  2.   

    问题解决了,就是照着你说的那样做,谢谢了!我想加个功能,就是在最后要执行“US12345678 + 回车”前能否先弹出一个messagebox提示用户呢,我对于线程这块不是很熟悉,谢谢了!