zoukankan      html  css  js  c++  java
  • C# 调用外部.exe文件

     #region "压缩文件"
            public static int  ExecZip(string zipPath,string csvPath)
            {
                //声明一个程序信息类
                System.Diagnostics.ProcessStartInfo Info = new System.Diagnostics.ProcessStartInfo();
    
                string fn = System.Configuration.ConfigurationManager.AppSettings["ZipExe"].ToString();
                //设置外部程序名
                // Info.FileName = @"C:Program FilesAmazon_ToolsXml2CSVzip.exe";
                Info.FileName =fn;
    
                //设置外部程序的启动参数(命令行参数)为test.txt
                Info.Arguments =@" "+ """+zipPath +"""+"  "+"""+csvPath+""";            
                //设置外部程序工作目录为  C:/
                Info.WorkingDirectory = @"D:";
                //声明一个程序类
                System.Diagnostics.Process Proc;
                try
                {
                    //启动外部程序              
                    Proc = System.Diagnostics.Process.Start(Info);
                }
                catch (Exception e)
                {
                    Console.WriteLine("文件压缩错误", e);
                    Console.Read();
                    return 1;
                }
    
                ////等待3秒钟
                Proc.WaitForExit(10000);
    
                //如果这个外部程序没有结束运行则对其强行终止
                if (Proc.HasExited == false)
                {
                   
                    Proc.Kill();
                }
                else
                {
                    Tools.writeText("调用压缩软件成功");
                }
                return Proc.ExitCode;
            }
            #endregion

    注意:路径中不能有空格,空格默认为回车

  • 相关阅读:
    [bzoj3524]Couriers
    [bzoj2789]Letters
    [bzoj4318]OSU!
    [luogu4570]元素
    [hdu6600]Just Skip The Problem
    [bzoj5025]单调上升路径
    [bzoj4557]侦察守卫
    [hdu5379]Mahjong tree
    [bzoj2957]楼房重建
    [noi253]A
  • 原文地址:https://www.cnblogs.com/WangYunyun/p/3309680.html
Copyright © 2011-2022 走看看