• 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

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

  • 相关阅读:
    2018.09.25python学习第十天part3
    2018.09.25python学习第十天part2
    2018.09.25python学习第十天part1
    2018.09.21python学习第九天part3
    2018.09.21python学习第九天part2
    2018.09.21python学习第九天part1
    2018.09.20python作业
    Alpha 冲刺(3/10)
    Alpha 冲刺(2/10)
    Alpha 冲刺(1/10)
  • 原文地址:https://www.cnblogs.com/WangYunyun/p/3309680.html
Copyright © 2020-2023  润新知