在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
主要功能如下 /// <summary> /// 上传文件 /// </summary> /// <param name="filePath">保存文件地址</param> /// <param name="maxSize">文件最大大小</param> /// <param name="fileType">文件后缀类型</param> /// <param name="TargetFile">控件名</param> /// <param name="saveFileName">保存后的文件名和地址</param> /// <param name="fileSize">文件大小</param> /// <returns></returns> 看下面代码吧 using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; using System.Diagnostics; namespace AutoApk { /// <summary> /// Cmd 的摘要说明。 /// </summary> public class Cmd { private Process proc = null; /// <summary> /// 构造方法 /// </summary> public Cmd() { proc = new Process(); } /// <summary> /// 执行CMD语句 /// </summary> /// <param name="cmd">要执行的CMD命令</param> public string RunCmd(string cmd) { proc.StartInfo.CreateNoWindow = true; proc.StartInfo.FileName = "cmd.exe"; proc.StartInfo.UseShellExecute = false; proc.StartInfo.RedirectStandardError = true; proc.StartInfo.RedirectStandardInput = true; proc.StartInfo.RedirectStandardOutput = true; proc.Start(); proc.StandardInput.WriteLine(cmd.Substring(0, cmd.IndexOf(":")) + ":"); cmd = "cd " + cmd; foreach (var item in cmd.Split(',')) { proc.StandardInput.WriteLine(item); } proc.StandardInput.WriteLine("exit"); string outStr = proc.StandardOutput.ReadToEnd(); proc.Close(); return outStr; } /// <summary> /// 打开软件并执行命令 /// </summary> /// <param name="programName">软件路径加名称(.exe文件)</param> /// <param name="cmd">要执行的命令</param> public void RunProgram(string programName, string cmd) { Process proc = new Process(); proc.StartInfo.CreateNoWindow = true; proc.StartInfo.FileName = programName; proc.StartInfo.UseShellExecute = false; proc.StartInfo.RedirectStandardError = true; proc.StartInfo.RedirectStandardInput = true; proc.StartInfo.RedirectStandardOutput = true; proc.Start(); if (cmd.Length != 0) { proc.StandardInput.WriteLine(cmd); } proc.Close(); } /// <summary> /// 打开软件 /// </summary> /// <param name="programName">软件路径加名称(.exe文件)</param> public void RunProgram(string programName) { this.RunProgram(programName, ""); } } }
|
请发表评论