本文整理汇总了C#中System.Diagnostics.Process.Close方法的典型用法代码示例。如果您正苦于以下问题:C# Process.Close方法的具体用法?C# Process.Close怎么用?C# Process.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Diagnostics.Process
的用法示例。
在下文中一共展示了Process.Close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DeZip
/// <summary>
/// 解压缩
/// </summary>
/// <param name="zipname">要解压的文件名</param>
/// <param name="zippath">要解压的文件路径</param>
public static void DeZip(string zipname, string zippath)
{
try
{
the_Reg = Registry.ClassesRoot.OpenSubKey(@"Applications\WinRar.exe\Shell\Open\Command");
the_Obj = the_Reg.GetValue("");
the_rar = the_Obj.ToString();
the_Reg.Close();
the_rar = the_rar.Substring(1, the_rar.Length - 7);
the_Info = " X " + zipname + " " + zippath;
the_StartInfo = new ProcessStartInfo();
the_StartInfo.FileName = the_rar;
the_StartInfo.Arguments = the_Info;
the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
the_Process = new Process();
the_Process.StartInfo = the_StartInfo;
the_Process.Start();
the_Process.WaitForExit();
the_Process.Close();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
示例2: Button1Click
void Button1Click(object sender, EventArgs e)
{
Process myProcess = new Process();
ProcessStartInfo myProcessStartInfo = new ProcessStartInfo(@"C:\Users\IJMAIL\AppData\Roaming\Nox\bin\nox_adb.exe" );
myProcessStartInfo.Arguments = "devices";
myProcessStartInfo.UseShellExecute = false;
myProcessStartInfo.RedirectStandardOutput = true; // 데이터 받기
myProcessStartInfo.RedirectStandardError = true; // 오류내용 받기
myProcessStartInfo.CreateNoWindow = true; // 원도우창 띄우기(true 띄우지 않기, false 띄우기)
myProcess.StartInfo = myProcessStartInfo;
myProcess.Start();
myProcess.WaitForExit();
//string output = myProcess.StandardOutput.ReadToEnd();
string output = myProcess.StandardOutput.ReadToEnd();
string error = myProcess.StandardError.ReadToEnd();
string[] aa = output.Split('\n');
for(int i=1; i<aa.Length; i++) {
listBox1.Items.Add(aa[i]);
}
//listBox1.Items.Add(aa.Length);
//listBox1.Items.Add(aa[1]);
//listBox1.Text = output;
// 프로그램이 종료되면
//System.Console.WriteLine( "ExitCode is " + myProcess.ExitCode );
myProcess.WaitForExit();
myProcess.Close();
}
示例3: Convert
public bool Convert(string input, string outputName)
{
try
{
Console.WriteLine("input:" + input);
Console.WriteLine("outputName:" + outputName);
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = "BabylonExport.exe";
p.StartInfo.Arguments = "/i:" + input + " /o:" + outputName;
p.Start();
if (p.WaitForExit(1000 * 60 * 3))
{
p.Close();
return true;
}
else
{
p.Close();
return false;
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return false;
}
}
示例4: RunCommand
//-------------------------------------------------------------------------
public static string RunCommand( string command )
{
string output = "";
using( Process p = new Process() )
{
p.StartInfo.CreateNoWindow = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "p4.exe";
p.StartInfo.Arguments = command;
p.StartInfo.ErrorDialog = true;
if( Program.LoggedOnUser != null )
{
p.StartInfo.EnvironmentVariables.Add(
"P4USER",
Program.LoggedOnUser.Username );
}
p.Start();
output = p.StandardOutput.ReadToEnd();
p.WaitForExit( 1000 );
p.Close();
}
return output;
}
示例5: SyncStart
public bool SyncStart(string CmdName, string CmdArgv)
{
m_Proc = new Process();
m_Proc.StartInfo.FileName = CmdName;
m_Proc.StartInfo.Arguments = CmdArgv;
m_Proc.StartInfo.CreateNoWindow = true;
m_Proc.StartInfo.UseShellExecute = false;
m_Proc.StartInfo.RedirectStandardInput = true;//标准输入重定向
m_Proc.StartInfo.RedirectStandardOutput = true;//标准输出重定向
m_Proc.StartInfo.RedirectStandardError = true;
m_Proc.Start();
StreamReader reader = m_Proc.StandardOutput;
m_Proc.WaitForExit();
m_RetOutputMsg = new StringBuilder();
m_RetOutputMsg.Append(reader.ReadToEnd());
reader = m_Proc.StandardError;
m_RetErrorMsg = reader.ReadToEnd();
int RetCode = m_Proc.ExitCode;
m_Proc.Close();
reader.Close();
if (RetCode == 0)
{
return true;
}
else
{
return false;
}
}
示例6: ExeCommand
///
/// 执行多条cmd.exe命令
///
///命令文本数组
/// 命令输出文本
public static string ExeCommand(string[] commandTexts)
{
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
string strOutput = null;
try
{
p.Start();
foreach (string item in commandTexts)
{
p.StandardInput.WriteLine(item);
}
p.StandardInput.WriteLine("exit");
strOutput = p.StandardOutput.ReadToEnd();
//strOutput = Encoding.UTF8.GetString(Encoding.Default.GetBytes(strOutput));
p.WaitForExit();
p.Close();
}
catch (Exception e)
{
strOutput = e.Message;
}
return strOutput;
}
示例7: WinrarProcess
private bool WinrarProcess(string arguments)
{
try
{
Process winrar = new Process();
winrar.StartInfo.FileName = "winrar.exe";
winrar.StartInfo.CreateNoWindow = true;
winrar.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
winrar.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;
winrar.StartInfo.Arguments = arguments;
winrar.Start();
winrar.WaitForExit();
if (winrar.HasExited)
{
int iExitCode = winrar.ExitCode;
if (iExitCode == 0)
{
//正常完成
return true;
}
else
{
//有错
return false;
}
}
winrar.Close();
return false;
}
catch
{
return false;
}
}
示例8: Cmd
/// <summary>
/// 执行命令行
/// </summary>
/// <param name="cmd"></param>
/// <returns></returns>
public static string Cmd(string command)
{
string output = ""; //输出字符串
if (command != null && !command.Equals(""))
{
Process process = new Process();//创建进程对象
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "cmd.exe";//设定需要执行的命令
startInfo.Arguments = "/C " + command;//“/C”表示执行完命令后马上退出
startInfo.UseShellExecute = false;//不使用系统外壳程序启动
startInfo.RedirectStandardInput = false;//不重定向输入
startInfo.RedirectStandardOutput = true; //重定向输出
startInfo.CreateNoWindow = true;//不创建窗口
process.StartInfo = startInfo;
try
{
if (process.Start())//开始进程
{
process.WaitForExit();//这里无限等待进程结束
output = process.StandardOutput.ReadToEnd();//读取进程的输出
}
}
catch
{
}
finally
{
if (process != null)
process.Close();
}
}
return output;
}
示例9: Run
public static void Run(string testArgument, DataReceivedEventHandler dataReceived = null)
{
string jarArgs = String.Format("{0} {1}", JavaArgs, testArgument);
var processInfo = new ProcessStartInfo(JavaExecutable, jarArgs)
{
CreateNoWindow = true,
UseShellExecute = false, // redirected streams
// redirect output stream
RedirectStandardOutput = true,
RedirectStandardError = true,
RedirectStandardInput = true
};
_process = new Process { StartInfo = processInfo, EnableRaisingEvents = true };
_process.OutputDataReceived += ProcessOnOutputDataReceived;
_process.ErrorDataReceived += ProcessOnErrorDataReceived;
if (dataReceived != null)
{
_process.OutputDataReceived += dataReceived;
_process.ErrorDataReceived += dataReceived;
}
_process.Start();
Trace.WriteLine("Java process started.");
_process.BeginOutputReadLine();
_process.BeginErrorReadLine();
Trace.WriteLine("Waiting for Java process to exit.");
_process.WaitForExit();
Trace.WriteLine("Java process exited.");
_process.Close();
}
示例10: FormatFile
private static void FormatFile(string sFile)
{
try
{
if ((File.GetAttributes(sFile) & FileAttributes.ReadOnly) != FileAttributes.ReadOnly)
{
// Make sure it's an xml file
XmlDocument doc = new XmlDocument();
doc.Load(sFile);
// It is, so now process it.
using (Process myProcess = new Process())
{
string workingDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase).Substring(6);
Console.WriteLine("Formatting {0}", sFile);
myProcess.StartInfo.FileName = Path.Combine(workingDir, @"Xmlformatter\XMLFormat");
myProcess.StartInfo.Arguments = sFile + " " + workingDir;
myProcess.StartInfo.CreateNoWindow = true;
myProcess.Start();
while (!myProcess.HasExited)
{} // Wait until it gets done.
myProcess.Close();
}
}
}
catch (XmlException xmlerr)
{
Console.WriteLine("Error message: {0}.", xmlerr.Message);
Console.WriteLine("Error: {0} is not an xml file!", sFile);
}
catch (Exception err)
{
Console.WriteLine("Error: " + err.Message);
}
}
示例11: CmdPing
public static bool CmdPing(string strIp)
{
bool pingRst = false;
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
p.StandardInput.WriteLine("ping -n 1 " + strIp);
p.StandardInput.WriteLine("exit");
string strRst = p.StandardOutput.ReadToEnd();
if (strRst.IndexOf("(0% loss)") != -1 || strRst.IndexOf("(0% 丢失)") != -1)
pingRst = true;
else
pingRst = false;
p.Close();
return pingRst;
}
示例12: PreprocessAndRun
/// <summary>
/// Preprocesses and runs Mike She
/// Note that if the MzLauncher is used it uses the execution engine flags from the .she-file
/// </summary>
/// <param name="MsheFileName"></param>
/// <param name="UseMZLauncher"></param>
public static void PreprocessAndRun(string MsheFileName, bool UseMZLauncher)
{
Process Runner = new Process();
string path;
DHIRegistry key = new DHIRegistry(DHIProductAreas.COMMON_COMPONNETS, false);
key.GetHomeDirectory(out path);
if (UseMZLauncher)
{
Runner.StartInfo.FileName = Path.Combine(path,"Mzlaunch.exe");
Runner.StartInfo.Arguments = Path.GetFullPath(MsheFileName) + " -exit";
}
else
{
Runner.StartInfo.FileName = Path.Combine(path,"Mshe_preprocessor.exe");
Runner.StartInfo.Arguments = MsheFileName;
Runner.Start();
Runner.WaitForExit();
Runner.StartInfo.FileName = Path.Combine(path,"Mshe_watermovement.exe");
}
Runner.Start();
Runner.WaitForExit();
Runner.Close();
}
示例13: RunCommand
/// <summary>
/// Runs the command. (*.cmd, *.bat, *.exe, etc.)
/// </summary>
/// <param name="commandFilePath">The command file path. (*.cmd, *.bat, *.exe, etc.)</param>
/// <param name="outputDelegate">The output delegate.</param>
public static void RunCommand(string commandFilePath, Action<string> outputDelegate)
{
if (!string.IsNullOrWhiteSpace(commandFilePath) && File.Exists(commandFilePath))
{
Process batProcess = new Process();
// Redirect the output stream of the child process.
batProcess.StartInfo.UseShellExecute = false;
batProcess.StartInfo.RedirectStandardOutput = true;
batProcess.StartInfo.RedirectStandardError = true;
batProcess.StartInfo.FileName = commandFilePath;
if (outputDelegate != null)
{
batProcess.OutputDataReceived += (sender, args) => outputDelegate(args.Data);
batProcess.ErrorDataReceived += (sender, args) => outputDelegate(args.Data);
}
batProcess.Start();
batProcess.BeginOutputReadLine();
batProcess.WaitForExit();
batProcess.Close();
}
}
示例14: runCommandAndGetOutput
public static int runCommandAndGetOutput(string exeFile, string args, ref string output)
{
string str = null;
Process process = new Process();
int exitCode = -1;
ProcessStartInfo info = new ProcessStartInfo {
FileName = exeFile,
Arguments = args,
RedirectStandardOutput = true,
CreateNoWindow = true,
UseShellExecute = false,
RedirectStandardError = true
};
process.StartInfo = info;
try
{
process.Start();
process.WaitForExit();
str = process.StandardError.ReadToEnd() + process.StandardOutput.ReadToEnd();
exitCode = process.ExitCode;
output = str;
process.Close();
return exitCode;
}
catch (Exception exception)
{
output = exception.Message;
return -1;
}
}
示例15: Run
private void Run(ReceivePack rp, string hook) {
var processStartInfo = new ProcessStartInfo {
FileName = hook, UseShellExecute = false,
WindowStyle = ProcessWindowStyle.Hidden, CreateNoWindow = true,
RedirectStandardOutput = true, RedirectStandardError = true,
RedirectStandardInput = true,
WorkingDirectory = FullPath
};
var appSettings = AppSettings.Current;
using(var process = new Process { StartInfo = processStartInfo }) {
if(!appSettings.RunHooksSilently) {
process.OutputDataReceived += (d, r) => { if(!String.IsNullOrWhiteSpace(r.Data)) rp.sendMessage(r.Data); };
process.ErrorDataReceived += (d, r) => { if(!String.IsNullOrWhiteSpace(r.Data)) rp.sendError(r.Data); };
}
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
foreach(var command in rp.getAllCommands()) {
process.StandardInput.WriteLine(command.getOldId().Name + " " + command.getNewId().Name + " " +
command.getRefName());
}
process.StandardInput.Close();
process.WaitForExit((int) appSettings.HookTimeout.TotalMilliseconds);
process.WaitForExit();
process.Close();
}
}