本文整理汇总了C#中Process.Close方法的典型用法代码示例。如果您正苦于以下问题:C# Process.Close方法的具体用法?C# Process.Close怎么用?C# Process.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Process
的用法示例。
在下文中一共展示了Process.Close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
public static int Execute(string CommandLineArgs )
{
int exitCode = 0 ;
try
{
Process process=new Process();
process.StartInfo.FileName="xmlsign.exe" ;
process.StartInfo.UseShellExecute=false;
process.StartInfo.RedirectStandardOutput=true;
process.StartInfo.RedirectStandardInput=true;
process.StartInfo.RedirectStandardError=true;
process.StartInfo.CreateNoWindow=true;
if( CommandLineArgs != null )
process.StartInfo.Arguments = CommandLineArgs ;
process.Start();
Console.WriteLine( process.StandardOutput.ReadToEnd() ) ;
process.WaitForExit();
exitCode = process.ExitCode ;
process.Close();
}
catch(Exception e)
{
Console.WriteLine( e ) ;
exitCode = -1;
}
return exitCode ;
}
示例2: UpcomingCalenderListText
public static void UpcomingCalenderListText()
{
// Initialize the process and its StartInfo properties.
// The sort command is a console application that
// reads and sorts text input.
Process calenderProcess;
calenderProcess = new Process();
calenderProcess.StartInfo.FileName = exeLocation;
// Set UseShellExecute to false for redirection.
calenderProcess.StartInfo.UseShellExecute = false;
// Redirect the standard output of the sort command.
// This stream is read asynchronously using an event handler.
calenderProcess.StartInfo.RedirectStandardOutput = true;
calendarOutput = new StringBuilder("");
// Set our event handler to asynchronously read the sort output.
calenderProcess.OutputDataReceived += new DataReceivedEventHandler(CalendarUpcomingEventsOutputHandler);
// Redirect standard input as well. This stream
// is used synchronously.
calenderProcess.StartInfo.RedirectStandardInput = true;
// Start the process.
calenderProcess.Start();
// Use a stream writer to synchronously write the sort input.
// StreamWriter sortStreamWriter = sortProcess.StandardInput;
// Start the asynchronous read of the sort output stream.
calenderProcess.BeginOutputReadLine();
// Wait for the sort process to write the sorted text lines.
calenderProcess.WaitForExit();
if (numOutputLines > 0)
{
// Write the formatted and sorted output to the console.
UnityEngine.Debug.Log(" Calender Upcoming event results = " + numOutputLines);
UnityEngine.Debug.Log(calendarOutput);
}
else
{
Console.WriteLine(" No entries found.");
}
calenderProcess.Close();
}
示例3: Button1_Click
protected void Button1_Click(object sender, EventArgs e)
{
CodeDomProvider codeProvider = CodeDomProvider.CreateProvider("CSharp");
string Output = "Out.exe";
Button ButtonObject = (Button)sender;
TextBox3.Text = "";
System.CodeDom.Compiler.CompilerParameters parameters = new CompilerParameters();
parameters.GenerateExecutable = true;
parameters.OutputAssembly = Output;
CompilerResults results = codeProvider.CompileAssemblyFromSource(parameters, TextBox2.Text);
if (results.Errors.Count > 0)
{
foreach (CompilerError CompErr in results.Errors)
{
TextBox3.Text = TextBox3.Text +
"Line number " + CompErr.Line +
", Error Number: " + CompErr.ErrorNumber +
", '" + CompErr.ErrorText + ";" +
Environment.NewLine + Environment.NewLine;
}
}
else
{
TextBox3.Text = "Success!";
#region
if (ButtonObject.Text == "EXECUTE")
{
Process myProcess = new Process();
ProcessStartInfo myProcessStartInfo = new ProcessStartInfo(Output);
myProcessStartInfo.UseShellExecute = false;
myProcessStartInfo.RedirectStandardOutput = true;
myProcess.StartInfo = myProcessStartInfo;
myProcess.Start();
StreamReader myStreamReader = myProcess.StandardOutput;
string myString = myStreamReader.ReadLine();
myProcess.WaitForExit();
myProcess.Close();
TextBox3.Text = myString;
}
#endregion
}
}
示例4: CheckDock
public static bool CheckDock(string DockPath)
{
//试运行
Process myProcess = new Process();
//string viewFiles = "tar -tf " + fileName + " ";
myProcess.StartInfo.FileName = DockPath;
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.RedirectStandardOutput = true;
// myProcess.StartInfo.Arguments = "-c ' " + viewFiles + " ' ";
myProcess.Start();
string output = myProcess.StandardOutput.ReadToEnd();
myProcess.Close();
if (output == "")
return false;
else
return true;
}
示例5: ScanFile
/*
* the true ClamAV link
* this will load clamdscan and wait for the result
*/
private void ScanFile()
{
string output = null;
try
{
Working = true;
Process ClamScan = new Process();
ClamScan.StartInfo.FileName = virtualPath + "clamscan.exe";
//ClamScan.StartInfo.Arguments = "--no-summary --move=" + (char)(34) + virtualPath + "quarantene" + (char)(34) + " " + (char)(34) + FileScan + (char)(34);
ClamScan.StartInfo.Arguments = " -r " + FileScan + " -d " +database;
ClamScan.StartInfo.CreateNoWindow = true;
ClamScan.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
ClamScan.StartInfo.RedirectStandardOutput = true;
ClamScan.StartInfo.UseShellExecute = false;
ClamScan.EnableRaisingEvents = true;
ClamScan.Start();
ClamScan.WaitForExit();
output = ClamScan.StandardOutput.ReadLine();
//output = ClamScan.StandardOutput.ReadToEnd();
//Console.WriteLine(" -r "+FileScan+" -d "+database+"hi"+output.ToString());
Console.WriteLine("output:"+output);
new insertIntoDatabase("output:" + output);
while (!ClamScan.HasExited)
{
Console.WriteLine("Waiting for thread close");
}
ClamScan.Close();
ClamScan.Dispose();
}
catch (Exception ex)
{
Console.WriteLine("ERROR: " + ex.Message);
}
Working = false;
if (output != null && output.Length > 0 && !output.EndsWith(": OK") && !output.EndsWith("ERROR") && output.Contains("FOUND"))
{
Console.WriteLine(output.EndsWith(":OK").ToString());
//ThreadHub.VirusFound(output);
}
//ThreadHub.EndScanThread(FileScan);
}
示例6: ExecuteCmd
/// <summary>
/// 执行系统CMD命令
/// </summary>
/// <param name="cmdList">命令集合</param>
/// <returns>//输出命令日志</returns>
public static string ExecuteCmd(ArrayList cmdList)
{
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
// 这里是关键点,不用Shell启动/重定向输入/重定向输出/不显示窗口
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
foreach (string item in cmdList)
{
p.StandardInput.WriteLine(item);
}
p.StandardInput.WriteLine("exit");//退出
p.WaitForExit(60000);
string s = p.StandardOutput.ReadToEnd();// 得到cmd.exe的输出
p.Close();
return s;//输出命令日志
}
示例7: Main
public static int Main(string[] args)
{
var proc = new Process();
proc.StartInfo.FileName = CygPath() + "\\bin\\mintty.exe";
proc.StartInfo.Arguments = "-";
proc.StartInfo.UseShellExecute = false;
try
{
proc.Start();
proc.WaitForExit();
return proc.ExitCode;
}
catch (SystemException e)
{
MessageBox.Show(e.Message + e.StackTrace, proc.StartInfo.FileName, MessageBoxButtons.OK);
return 255;
}
finally
{
proc.Close();
}
}
示例8: Ejecutar
public string Ejecutar(bool Redireccionar)
{
string Res;
Process Pro;
Res = "";
Pro = new Process ();
Pro.StartInfo.FileName = FNombre;
Pro.StartInfo.Arguments = FParametros;
if (Redireccionar) {
Pro.StartInfo.RedirectStandardInput = true;
Pro.StartInfo.RedirectStandardOutput = true;
Pro.StartInfo.UseShellExecute = false;
Pro.StartInfo.CreateNoWindow = true;
}
Pro.Start ();
if (Redireccionar) {
Pro.WaitForExit ();
Res = Pro.StandardOutput.ReadToEnd ();
}
Pro.Close ();
Pro.Dispose ();
return Res;
}
示例9: CompressRAR
/// <summary>
/// 打包成Rar
/// </summary>
/// <param name="patch"></param>
/// <param name="rarPatch"></param>
/// <param name="rarName"></param>
public void CompressRAR(string patch, string rarPatch, string rarName)
{
string the_rar;
RegistryKey the_Reg;
object the_Obj;
string the_Info;
ProcessStartInfo the_StartInfo;
Process the_Process;
try
{
the_Reg = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\WinRAR.exe");
the_Obj = the_Reg.GetValue("");
the_rar = the_Obj.ToString();
the_Reg.Close();
the_rar = the_rar.Substring(1, the_rar.Length - 7);
Directory.CreateDirectory(patch);
//命令参数
//the_Info = " a " + rarName + " " + @"C:Test?70821.txt"; //文件压缩
the_Info = " a " + rarName + " " + patch + " -r"; ;
the_StartInfo = new ProcessStartInfo();
the_StartInfo.FileName = the_rar;
the_StartInfo.Arguments = the_Info;
the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
//打包文件存放目录
the_StartInfo.WorkingDirectory = rarPatch;
the_Process = new Process();
the_Process.StartInfo = the_StartInfo;
the_Process.Start();
the_Process.WaitForExit();
the_Process.Close();
}
catch (Exception ex)
{
throw ex;
}
}
示例10: CreateThumbnail
private void CreateThumbnail(string uniqueId, string svgInput, string visType)
{
string workingDir=string.Empty, filePath=string.Empty, command=string.Empty, svg_folder = "libraries\\svg_rasterizer\\", storagePath = "stock\\shared\\vc\\";
FileStream fileStream = null;
Process dosProcess = null;
if (visType.ToLower().Equals("treemap"))
{
File.Copy(Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, "stock\\templates\\fb_treemap.png"), Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, storagePath + "treemap\\" + uniqueId + ".png"));
return;
}
else if (visType.ToLower().Equals("radar"))
{
File.Copy(Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, "stock\\templates\\fb_radar.jpg"), Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, storagePath + uniqueId + ".jpg"));
return;
}
dosProcess = new Process();
workingDir = Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, svg_folder);
filePath = Path.Combine(workingDir, uniqueId + Constants.XLSDownloadType.SvgExtention);
fileStream = File.Create(filePath);
fileStream.Close();
using (StreamWriter sw = new StreamWriter(filePath))
{
sw.Write(svgInput);
}
command = "/C java -jar " + Constants.XLSDownloadType.BatikRasterizerJarFile + " " + Constants.XLSDownloadType.ImageType + " " + uniqueId + Constants.XLSDownloadType.SvgExtention;
ProcessStartInfo startInfo = new ProcessStartInfo("cmd.exe");
startInfo.UseShellExecute = false;
startInfo.WorkingDirectory = workingDir;
startInfo.Arguments = command;
startInfo.CreateNoWindow = true;
dosProcess.StartInfo = startInfo;
dosProcess.Start();
dosProcess.WaitForExit();
dosProcess.Close();
File.Move(Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, svg_folder) + uniqueId + ".png", Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, storagePath + uniqueId + "_big.png"));
SaveThumbnail(Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, storagePath + uniqueId + "_big.png"), Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, storagePath + uniqueId + ".png"), 200, 200);
if(File.Exists(Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, storagePath + uniqueId + "_big.png")))
{
File.Delete(Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, storagePath + uniqueId + "_big.png"));
}
}
示例11: GetVideoDuration
//获取视频长度
public static TimeSpan GetVideoDuration(string filePath, string ffmpegExePath)
{
try
{
string output = "";
if (File.Exists(ffmpegExePath))
{
//视频长度
Process p = new Process();//建立外部调用线程
p.StartInfo.FileName = ffmpegExePath;
p.StartInfo.Arguments = string.Format(@"-i ""{0}""", filePath);
p.StartInfo.UseShellExecute = false;//不使用操作系统外壳程序启动线程
p.StartInfo.RedirectStandardError = true;//把外部程序错误输出写到StandardError流中
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.StartInfo.CreateNoWindow = true;//不创建进程窗口
p.Start();//启动线程
p.WaitForExit(2500);//等待完成
output = p.StandardError.ReadToEnd();//开始同步读取
p.Close();//关闭进程
p.Dispose();//释放资源
}
var reg = new Regex(@"Duration: (?<h>\d+):(?<m>\d+):(?<s>\d+)\.(?<ms>\d+)");
var match = reg.Match(output);
if (!match.Success)
{
var info = Read(filePath);
return info.Time;
}
else
{
return new TimeSpan(0, int.Parse(match.Groups["h"].Value),
int.Parse(match.Groups["m"].Value),
int.Parse(match.Groups["s"].Value),
int.Parse(match.Groups["ms"].Value));
}
}
catch
{
return new TimeSpan(0, 0, 1);
}
}
示例12: Execute
public static string Execute(string dosCommand, int milliseconds)
{
string output = ""; //输出字符串
if (dosCommand != null && dosCommand != "")
{
Process process = new Process(); //创建进程对象
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "cmd.exe"; //设定需要执行的命令
startInfo.Arguments = "/C " + dosCommand; //设定参数,其中的“/C”表示执行完命令后马上退出
startInfo.UseShellExecute = false; //不使用系统外壳程序启动
startInfo.RedirectStandardInput = false; //不重定向输入
startInfo.RedirectStandardOutput = true; //重定向输出
startInfo.CreateNoWindow = true; //不创建窗口
process.StartInfo = startInfo;
try
{
if (process.Start()) //开始进程
{
if (milliseconds == 0)
process.WaitForExit(); //这里无限等待进程结束
else
process.WaitForExit(milliseconds); //这里等待进程结束,等待时间为指定的毫秒
output = process.StandardOutput.ReadToEnd();//读取进程的输出
}
}
catch
{
}
finally
{
if (process != null)
process.Close();
}
}
return output;
}
示例13: unCompressRAR
/// <summary>
/// 解压
/// </summary>
/// <param name="unRarPatch"></param>
/// <param name="rarPatch"></param>
/// <param name="rarName"></param>
/// <returns></returns>
public string unCompressRAR(string unRarPatch, string rarPatch, string rarName)
{
string the_rar;
RegistryKey the_Reg;
object the_Obj;
string the_Info;
try
{
the_Reg = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\WinRAR.exe");
the_Obj = the_Reg.GetValue("");
the_rar = the_Obj.ToString();
the_Reg.Close();
//the_rar = the_rar.Substring(1, the_rar.Length - 7);
if (Directory.Exists(unRarPatch) == false)
{
Directory.CreateDirectory(unRarPatch);
}
the_Info = "e " + rarName + " " + unRarPatch + " -y";
ProcessStartInfo the_StartInfo = new ProcessStartInfo();
the_StartInfo.FileName = the_rar;
the_StartInfo.Arguments = the_Info;
the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
the_StartInfo.WorkingDirectory = rarPatch;//获取压缩包路径
Process the_Process = new Process();
the_Process.StartInfo = the_StartInfo;
the_Process.Start();
the_Process.WaitForExit();
the_Process.Close();
}
catch (Exception ex)
{
throw ex;
}
return unRarPatch;
}
示例14: build_code
protected void build_code(object sender, EventArgs e, string s)
{
string path = Server.MapPath("~/gcc_compiler/bin");
string output_path = Server.MapPath("~/cfiles");
string arg = " " + output_path + "\\test.c";
Process compiling_process = new Process();
ProcessStartInfo compiling_info = new ProcessStartInfo();
compiling_info.FileName = path + "\\gcc.exe";
compiling_info.UseShellExecute = false;
compiling_info.WorkingDirectory = path;
compiling_info.RedirectStandardOutput = true;
compiling_info.RedirectStandardInput = true;
compiling_info.RedirectStandardError = true;
compiling_info.Arguments = arg;
compiling_process.StartInfo = compiling_info;
compiling_process.Start();
compiling_process.WaitForExit();
string error_msg = compiling_process.StandardError.ReadToEnd();
string output_msg = compiling_process.StandardOutput.ReadToEnd();
compiling_process.Close();
if(output_msg=="" && error_msg=="")
output_area.InnerText = "Compiled Successfully. No errors";
else
output_area.InnerText = error_msg;
if(s=="run" && error_msg =="")
{
string path1 = Server.MapPath("~/cfiles//" + Session["username"] + "test_input.txt");
if (File.Exists(path1))
{
File.Delete(path1);
}
File.WriteAllText(@path1, input_value_area.Value.Trim());
Process myProcess = new Process();
ProcessStartInfo myProcessStartInfo = new ProcessStartInfo();
if (cmd_arg.Checked)
{
try
{
string args = input_value_area.Value.Trim();
myProcessStartInfo.Arguments = args;
}
catch (IndexOutOfRangeException re)
{
alert_already_exists.InnerText = "Your arguments array range is out of range. Please Check it";
}
}
myProcessStartInfo.FileName = path + "\\a.exe";
myProcessStartInfo.WorkingDirectory = path;
myProcessStartInfo.UseShellExecute = false;
myProcessStartInfo.RedirectStandardOutput = true;
myProcessStartInfo.RedirectStandardError = true;
myProcessStartInfo.RedirectStandardInput = true;
myProcess.StartInfo = myProcessStartInfo;
myProcess.Start();
string subline;
StreamWriter myStreamReaderInput = myProcess.StandardInput;
myStreamReaderInput.AutoFlush = true;
string input = input_value_area.Value.Trim();
System.IO.StreamReader f = new System.IO.StreamReader(path1);
while ((subline = f.ReadLine()) != null)
{
myStreamReaderInput.WriteLine(subline);
}
f.Close();
myStreamReaderInput.WriteLine();
myStreamReaderInput.Dispose();
myStreamReaderInput.Close();
myProcess.WaitForExit();
output_msg = myProcess.StandardOutput.ReadToEnd();
error_msg = myProcess.StandardError.ReadToEnd();
myProcess.Close();
if ((output_msg == "" && error_msg == "") || (output_msg != "" && error_msg == ""))
output_area.InnerText = output_msg;
else
output_area.InnerText = output_msg +Environment.NewLine+"Error:"+ error_msg;
}
}
示例15: zipDataBase
private bool zipDataBase(string str_databasepath, string str_database)
{
string rar;
string args;
ProcessStartInfo procStart;
//By mbq 20110531 Item W20 del Start
//Process process;
//By mbq 20110531 Item W20 del end
//By mbq 20110531 Item W20 add Start
Process process = new Process();
//By mbq 20110531 Item W20 add end
string databasedestinationpath = str_databasepath + "\\" + str_database;
try
{
if (System.IO.File.Exists(databasedestinationpath))
{
System.IO.File.Delete(databasedestinationpath);
}
}
catch (Exception ex)
{
return false;
}
try
{
rar = ConfigurationSettings.AppSettings["winrarpath"].ToString();
args = "a -inul -y -o+ -ep1 " + databasedestinationpath + " " + str_databasepath;
procStart = new ProcessStartInfo();
procStart.FileName = rar;
procStart.Arguments = args;
procStart.WorkingDirectory = Server.MapPath("");
// By mbq 20110531 Item W20 del Start
// process = new Process();
// By mbq 20110531 Item W20 del end
process.StartInfo = procStart;
process.Start();
process.WaitForExit();
// By mbq 20110531 Item W20 Add Start
process.Close();
// By mbq 20110531 Item W20 Add end
return true;
}
catch (Exception ex)
{
// By mbq 20110531 Item W20 Add Start
process.Close();
// By mbq 20110531 Item W20 Add end
Response.Close();
return false;
}
}