ASP.NET中使用C#调用服务器端exe可执行文件

执行调用事件的按钮:
      protected void btnCall_Click(object sender, EventArgs e)
        {
            try
            {
                CallSteven();

                lblMessage.Text = "完成调用";
                lblMessage.ForeColor = Color.Black;
            }
            catch (Exception exUpdate)
            {
                lblMessage.Text = exUpdate.Message.ToString();
                lblMessage.ForeColor = Color.Red;
            }
        }

 //调用可执行文件的方法
      public void CallSteven()
        {
            string strCmd = "";
            DateTime dt = DateTime.Now;
           
             //注意:需要引入System.Diagnostics;
            Process prc = new Process();

            try
            {
                //指定调用的可执行文件
                strCmd += "D://steven//steven.exe ";
  
                //如果可执行文件需要接收参数就加下下面这句,不同参数之间用空格隔开
                //strCmd += 参数1 + " " + 参数2 + " " + 参数n;

                //调用cmd.exe在命令提示符下执行可执行文件
                prc.StartInfo.FileName = "cmd.exe";
                prc.StartInfo.Arguments = " /c " + strCmd;
                prc.StartInfo.UseShellExecute = false;
                prc.StartInfo.RedirectStandardError = true;
                prc.StartInfo.RedirectStandardOutput = true;
                prc.StartInfo.RedirectStandardInput = true;
                prc.StartInfo.CreateNoWindow = false;

                prc.Start();

            }
            catch (Exception exU)
            {
                if (!prc.HasExited)
                {
                    prc.Close();
                }

                throw new Exception(exU.Message.ToString());
            }
        }

 使用上面的代码就可以实现对steven.exe的调用^_^

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值