当前位置: 首页>>代码示例>>C#>>正文


C# Process.Kill方法代码示例

本文整理汇总了C#中Process.Kill方法的典型用法代码示例。如果您正苦于以下问题:C# Process.Kill方法的具体用法?C# Process.Kill怎么用?C# Process.Kill使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Process的用法示例。


在下文中一共展示了Process.Kill方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: StartAndKillProcessWithDelay

 protected void StartAndKillProcessWithDelay(Process p)
 {
     p.Start();
     Sleep();
     p.Kill();
     Assert.True(p.WaitForExit(WaitInMS));
 }
开发者ID:healtech,项目名称:corefx,代码行数:7,代码来源:ProcessTestBase.cs

示例2: StartSleepKillWait

 protected void StartSleepKillWait(Process p)
 {
     p.Start();
     Thread.Sleep(50);
     p.Kill();
     Assert.True(p.WaitForExit(WaitInMS));
 }
开发者ID:ESgarbi,项目名称:corefx,代码行数:7,代码来源:ProcessTestBase.cs

示例3: RunRemote

    private static void RunRemote(int arg)
    {
        using (Process p = new Process())
        {
            try
            {
                ProcessStartInfo psi = new ProcessStartInfo();
                psi.FileName = "corerun";
                psi.Arguments = "EnvironmentExitConsoleApp.exe " + Convert.ToString(arg);
                psi.UseShellExecute = false;

                // Profilers / code coverage tools doing coverage of the test process set environment
                // variables to tell the targeted process what profiler to load.  We don't want the child process 
                // to be profiled / have code coverage, so we remove these environment variables for that process 
                // before it's started.
                psi.Environment.Remove("Cor_Profiler");
                psi.Environment.Remove("Cor_Enable_Profiling");
                psi.Environment.Remove("CoreClr_Profiler");
                psi.Environment.Remove("CoreClr_Enable_Profiling");

                p.StartInfo = psi;
                p.Start();
                Assert.True(p.WaitForExit(30 * 1000));

                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    Assert.Equal(arg, p.ExitCode);
                }
                else
                {
                    Assert.True(arg == p.ExitCode || arg == Convert.ToInt32(unchecked((sbyte)(p.ExitCode))));
                }

            }
            finally
            {
                // Cleanup
                try { p.Kill(); }
                catch { } // ignore all cleanup errors
            }
        }
    }
开发者ID:ReedKimble,项目名称:corefx,代码行数:42,代码来源:Environment.Exit.cs

示例4: Main

	public static int Main (string [] args)
	{
		if (args.Length < 1) {
			Console.WriteLine ("Specify the test to run.");
			return 1;
		}

		if (args [0] == "fork") {
#if MONO
			if (args.Length != 2) {
				Console.WriteLine ("Specify the path to the mono runtime.");
				return 2;
			}
#endif

			Process proc = new Process ();
#if MONO
			proc.StartInfo.FileName = args [1];
			proc.StartInfo.Arguments = "\"" + Path.Combine (AppDomain.CurrentDomain.BaseDirectory, "test.exe") + "\" test";
#else
			proc.StartInfo.FileName = Path.Combine (AppDomain.CurrentDomain.BaseDirectory, "test.exe");
			proc.StartInfo.Arguments = "test";
#endif
			proc.StartInfo.UseShellExecute = false;
			proc.StartInfo.RedirectStandardInput = true;
			proc.StartInfo.RedirectStandardOutput = true;
			proc.Start ();

			try {
				string output = proc.StandardOutput.ReadLine ();
				if (output != (new string ('h', 10000) + 'a'))
					return 1;
			} finally {
				proc.Kill ();
			}
		} else {
			Console.WriteLine (new string ('h', 10000) + 'a');
			Console.ReadLine ();
		}

		return 0;
	}
开发者ID:mono,项目名称:gert,代码行数:42,代码来源:test.cs

示例5: LaunchButton_Click

	void LaunchButton_Click (object sender, EventArgs e)
	{
		string consoleApp = Path.Combine (AppDomain.CurrentDomain.BaseDirectory,
			"console.exe");

		Process p = new Process ();
		p.StartInfo.CreateNoWindow = true;
		p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
		if (_runtimeEngine != null) {
			p.StartInfo.FileName = _runtimeEngine;
			p.StartInfo.Arguments = "\"" + consoleApp + "\"";
		} else {
			p.StartInfo.FileName = consoleApp;
		}
		p.StartInfo.UseShellExecute = false;
		p.StartInfo.RedirectStandardInput = true;
		p.StartInfo.RedirectStandardOutput = true;
		p.StartInfo.RedirectStandardError = true;
		p.Start ();

		MessageBox.Show ("Launched");

		p.Kill ();
	}
开发者ID:mono,项目名称:gert,代码行数:24,代码来源:MainForm.cs

示例6: Main


//.........这里部分代码省略.........

				lock (monitor) {
					fs = process_data [p2].stdout;

					if (String.IsNullOrEmpty (e.Data))
						process_data [p2].stdout = null;
				}

				if (String.IsNullOrEmpty (e.Data)) {
					fs.Close ();
				} else {
					fs.WriteLine (e.Data);
					fs.Flush ();
				}
			};

			p.ErrorDataReceived += delegate (object sender, DataReceivedEventArgs e) {
				Process p2 = (Process)sender;

				StreamWriter fs;

				lock (monitor) {
					fs = process_data [p2].stderr;

					if (String.IsNullOrEmpty (e.Data))
						process_data [p2].stderr = null;

				}

				if (String.IsNullOrEmpty (e.Data)) {
					fs.Close ();

					lock (monitor) {
						process_data [p2].stderr = null;
					}
				} else {
					fs.WriteLine (e.Data);
					fs.Flush ();
				}
			};

			lock (monitor) {
				processes.Add (p);
				process_data [p] = data;
			}
			p.Start ();

			p.BeginOutputReadLine ();
			p.BeginErrorReadLine ();
		}

		bool timed_out = false;

		/* Wait for all processes to terminate */
		while (true) {
			lock (monitor) {
				int nprocesses = processes.Count;

				if (nprocesses == 0)
					break;

				bool res = Monitor.Wait (monitor, 1000 * timeout);
				if (!res) {
					timed_out = true;
					break;
				}
			}
		}

		Console.WriteLine ();

		if (timed_out) {
			Console.WriteLine ("\nrunning tests timed out:\n");
			Console.WriteLine (npassed + nfailed);
			lock (monitor) {
				foreach (Process p in processes) {
					ProcessData pd = process_data [p];
					pd.CloseStreams ();
					Console.WriteLine (pd.test);
					p.Kill ();
					DumpFile (pd.stdoutFile);
					DumpFile (pd.stderrFile);
				}
			}
			return 1;
		}

		Console.WriteLine ("" + npassed + " test(s) passed. " + nfailed + " test(s) did not pass.");
		if (nfailed > 0) {
			Console.WriteLine ("\nFailed tests:\n");
			foreach (ProcessData pd in failed) {
				Console.WriteLine (pd.test);
				DumpFile (pd.stdoutFile);
				DumpFile (pd.stderrFile);
			}
			return 1;
		} else {
			return 0;
		}
	}
开发者ID:vargaz,项目名称:mono,代码行数:101,代码来源:test-runner.cs

示例7: Main


//.........这里部分代码省略.........
			object aot_monitor = new object ();
			var aot_queue = new Queue<String> (tests); 

			List<Thread> build_threads = new List<Thread> (concurrency);

			for (int j = 0; j < concurrency; ++j) {
				Thread thread = new Thread (() => {
					while (true) {
						String test_name;

						lock (aot_monitor) {
							if (aot_queue.Count == 0)
								break;
							test_name = aot_queue.Dequeue ();
						}

						string test_bitcode_output = test_name + "_bitcode_tmp";
						string test_bitcode_arg = ",temp-path=" + test_bitcode_output;
						string aot_args = aot_build_flags + test_bitcode_arg + " " + test_name;

						Directory.CreateDirectory(test_bitcode_output);

						ProcessStartInfo job = new ProcessStartInfo (runtime, aot_args);
						job.UseShellExecute = false;
						job.EnvironmentVariables[ENV_TIMEOUT] = timeout.ToString();
						job.EnvironmentVariables[MONO_PATH] = mono_path;
						Process compiler = new Process ();
						compiler.StartInfo = job;

						compiler.Start ();

						if (!compiler.WaitForExit (timeout * 1000)) {
							try {
								compiler.Kill ();
							} catch {
							}
							throw new Exception(String.Format("Timeout AOT compiling tests, output in {0}", test_bitcode_output));
						} else if (compiler.ExitCode != 0) {
							throw new Exception(String.Format("Error AOT compiling tests, output in {0}", test_bitcode_output));
						} else {
							Directory.Delete (test_bitcode_output, true);
						}
					}
				});

				thread.Start ();

				build_threads.Add (thread);
			}

			for (int j = 0; j < build_threads.Count; ++j)
				build_threads [j].Join ();

			Console.WriteLine("Done compiling");
		}

		List<Thread> threads = new List<Thread> (concurrency);

		DateTime test_start_time = DateTime.UtcNow;

		for (int j = 0; j < concurrency; ++j) {
			Thread thread = new Thread (() => {
				while (true) {
					TestInfo ti;

					lock (monitor) {
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:67,代码来源:test-runner.cs

示例8: TryGDB

	static void TryGDB (int pid, ProcessData data)
	{
		string filename = Path.GetTempFileName ();

		using (StreamWriter sw = new StreamWriter (new FileStream (filename, FileMode.Open, FileAccess.Write)))
		{
			sw.WriteLine ("attach " + pid);
			sw.WriteLine ("info threads");
			sw.WriteLine ("thread apply all p mono_print_thread_dump(0)");
			sw.WriteLine ("thread apply all backtrace");
			sw.Flush ();

			ProcessStartInfo psi = new ProcessStartInfo {
				FileName = "gdb",
				Arguments = "-batch -x \"" + filename + "\" -nx",
				UseShellExecute = false,
				RedirectStandardError = true,
				RedirectStandardOutput = true,
			};

			using (Process process = new Process { StartInfo = psi })
			{
				process.OutputDataReceived += delegate (object sender, DataReceivedEventArgs e) {
					lock (data.stdoutLock) {
						if (e.Data != null)
							data.stdout.AppendLine (e.Data);
					}
				};

				process.ErrorDataReceived += delegate (object sender, DataReceivedEventArgs e) {
					lock (data.stderrLock) {
						if (e.Data != null)
							data.stderr.AppendLine (e.Data);
					}
				};

				process.Start ();
				process.BeginOutputReadLine ();
				process.BeginErrorReadLine ();
				if (!process.WaitForExit (60 * 1000))
					process.Kill ();
			}
		}
	}
开发者ID:mono,项目名称:mono,代码行数:44,代码来源:test-runner.cs

示例9: TryLLDB

	static void TryLLDB (int pid, ProcessData data)
	{
		string filename = Path.GetTempFileName ();

		using (StreamWriter sw = new StreamWriter (new FileStream (filename, FileMode.Open, FileAccess.Write)))
		{
			sw.WriteLine ("process attach --pid " + pid);
			sw.WriteLine ("thread list");
			sw.WriteLine ("thread backtrace all");
			sw.WriteLine ("detach");
			sw.WriteLine ("quit");
			sw.Flush ();

			ProcessStartInfo psi = new ProcessStartInfo {
				FileName = "lldb",
				Arguments = "--batch --source \"" + filename + "\" --no-lldbinit",
				UseShellExecute = false,
				RedirectStandardError = true,
				RedirectStandardOutput = true,
			};

			using (Process process = new Process { StartInfo = psi })
			{
				process.OutputDataReceived += delegate (object sender, DataReceivedEventArgs e) {
					lock (data.stdoutLock) {
						if (e.Data != null)
							data.stdout.AppendLine (e.Data);
					}
				};

				process.ErrorDataReceived += delegate (object sender, DataReceivedEventArgs e) {
					lock (data.stderrLock) {
						if (e.Data != null)
							data.stderr.AppendLine (e.Data);
					}
				};

				process.Start ();
				process.BeginOutputReadLine ();
				process.BeginErrorReadLine ();
				if (!process.WaitForExit (60 * 1000))
					process.Kill ();
			}
		}
	}
开发者ID:mono,项目名称:mono,代码行数:45,代码来源:test-runner.cs

示例10: ChangeUserPrivilegesToLogOnAsService

        public static ActionResult ChangeUserPrivilegesToLogOnAsService(Session session)
        {
            return session.HandleErrors(() =>
            {
                string ntrightsPath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), @"ntrights.exe");
                string setupType = session.Property("SETUPTYPE");
                string currentLoggedInUser = session.Property("CURRENTLOGGEDINUSER");

                if (SetupType.Express.Equals(setupType, StringComparison.InvariantCultureIgnoreCase))
                {
                    SendProgressMessageToBA(session, "Granting user log on as service permission", 1);

                    session.SaveBinary("NtRights", ntrightsPath);

                    try
                    {
                        Process ntRightsProcess = new Process();

                        ntRightsProcess.StartInfo.FileName = ntrightsPath;
                        ntRightsProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                        ntRightsProcess.StartInfo.CreateNoWindow = true;
                        ntRightsProcess.StartInfo.UseShellExecute = false;
                        ntRightsProcess.StartInfo.Arguments = "+r SeServiceLogonRight -u \"" + currentLoggedInUser + "\"";

                        ntRightsProcess.Start();

                        ntRightsProcess.WaitForExit(ProcessExitWaitTime);

                        // This needs to be done as this process can wait for standard input in case of failure.
                        // We nicely kill this process ourselves in this case to not stop the setup from progressing.
                        if (!ntRightsProcess.HasExited)
                        {
                            ntRightsProcess.Kill();
                        }

                        if (ntRightsProcess.ExitCode == 0)
                        {
                            // [TODO] Add strings for localization
                            SendMessageBoxMessageToBA(session, string.Format("The account {0} has been granted the Log On As A Service right.",
                                                                    currentLoggedInUser));
                        }
                        else
                        {
                            SendMessageBoxMessageToBA(session, string.Format("The account {0} couldn't be grated the Log On As A Service right.",
                                                                    currentLoggedInUser));
                        }
                    }
                    catch (Exception e)
                    {
                        session.Log("[ChangeUserPrivilegesToLogOnAsService] {0}", e.Message);
                    }
                    finally
                    {
                        // We can safely try to delete this file here as Delete() doesn't throw exception for
                        // file not found.
                        System.IO.File.Delete(ntrightsPath);
                    }
                }
            });
        }
开发者ID:SonarQubeCommunity,项目名称:sonarqube-windows-installer,代码行数:60,代码来源:Program.cs

示例11: Run

            public AppExitStatus Run(BackgroundWorker worker, DoWorkEventArgs e)
            {
                try
                {
                   bool saveDef = opts.saveDefaultOutput,
                    saveErr = opts.saveErrorOutput;

                   ResetOutput();

                   Process objProcess = new Process();

                   if (!opts.wait)
                   {
                  saveDef = false;
                  saveErr = false;
                   }

                   if (opts.checkSuccessMethod == Software.CheckSuccessMethod.DEFAULTOUTPUT)
                  saveDef = true;

                   if (opts.checkSuccessMethod == Software.CheckSuccessMethod.ERROROUTPUT)
                  saveErr = true;

                   if (string.IsNullOrEmpty(opts.workingDirectory.Path))
                  opts.workingDirectory.Path = opts.exeFile.Path;

                   objProcess.StartInfo.CreateNoWindow = true;
                   objProcess.StartInfo.RedirectStandardOutput = saveDef;
                   objProcess.StartInfo.RedirectStandardError = saveErr;
                   objProcess.StartInfo.FileName = opts.exeFile.FullName;
                   objProcess.StartInfo.Arguments = opts.arguments;
                   objProcess.StartInfo.UseShellExecute = opts.useShell;
                   objProcess.StartInfo.WorkingDirectory = opts.workingDirectory.Path;

                   if (saveDef)
                  objProcess.OutputDataReceived += new DataReceivedEventHandler(NewOutputData);

                   if (saveErr)
                  objProcess.ErrorDataReceived += new DataReceivedEventHandler(NewErrorData);

                   objProcess.Start();

                   if (saveDef) objProcess.BeginOutputReadLine();
                   if (saveErr) objProcess.BeginErrorReadLine();

                   if (opts.wait)
                  objProcess.WaitForExit();
                   else
                   {
                  while (!objProcess.HasExited)
                  {
                     if (worker.CancellationPending)
                     {
                        objProcess.Kill();
                        return AppExitStatus.Canceled;
                     }
                     Thread.Sleep(200);
                  }
                   }

                   int exitCode = objProcess.ExitCode;

                   AppExitStatus successfull = AppExitStatus.Unknown;
                   switch (opts.checkSuccessMethod)
                   {
                  case Software.CheckSuccessMethod.EXITCODE:
                     if (exitCode == successExitCode)
                        successfull = AppExitStatus.Finished;
                     break;
                  case Software.CheckSuccessMethod.DEFAULTOUTPUT:
                     if (saveDef)
                     {
                        if (FindText(ref DefaultOutput))
                           successfull = AppExitStatus.Finished;
                        else
                           successfull = AppExitStatus.Failed;
                     }
                     break;
                  case Software.CheckSuccessMethod.ERROROUTPUT:
                     if (saveErr)
                     {
                        if (FindText(ref ErrorOutput))
                           successfull = AppExitStatus.Finished;
                        else
                           successfull = AppExitStatus.Failed;
                     }
                     break;
                  default:
                     successfull = AppExitStatus.Finished;
                     break;
                   }

                   exception = null;
                   return successfull;
                }
                catch (Exception ex)
                {
                   exception = ex;
                   return AppExitStatus.Exception;
                }
//.........这里部分代码省略.........
开发者ID:JauchOnGitHub,项目名称:csharptoolbox,代码行数:101,代码来源:ExternalApp.cs

示例12: BuildProxy

	static void BuildProxy (ServiceData fd, bool rebuild, ArrayList proxies, XmlElement errdoc)
	{
		string wsdl = GetWsdlFile (fd);
		if (!File.Exists (wsdl)) 
			return;
		
		if (fd.Protocols == null)
		{
			ReportError ("Client test '" + fd.Name + "': no protocols declared", "");
			return;
		}
		
		foreach (string prot in fd.Protocols)
		{
			string ns = fd.Namespace;
			ns = CodeIdentifier.MakeValid (ns) + "." + prot;
		
			string pfile = GetProxyFile (fd, prot);
			if (File.Exists (pfile) && !rebuild) { proxies.Add (pfile); continue; }
			
			CreateFolderForFile	(pfile);

			Console.Write (prot + " proxy for " + wsdl + "... ");
			Process proc = new Process ();
			proc.StartInfo.UseShellExecute = false;
			proc.StartInfo.RedirectStandardOutput = true;
			proc.StartInfo.RedirectStandardError = true;
			proc.StartInfo.FileName = "wsdl";
			proc.StartInfo.Arguments = "/out:" + pfile + " /nologo /namespace:" + ns + " /protocol:" + prot + " " + wsdl;
			proc.Start();
			
			if (!proc.WaitForExit (30000))
			{
				try {
					proc.Kill ();
				} catch {}
				
				Console.WriteLine ("FAIL (timeout)");
				if (File.Exists (pfile)) File.Delete (pfile);
				WriteError (errdoc, ns, "Errors found while generating " + prot + " proxy for WSDL: " + wsdl, "wsdl.exe timeout");
			}
			else if (proc.ExitCode != 0)
			{
				Console.WriteLine ("FAIL " + proc.ExitCode);
				
				string err = proc.StandardOutput.ReadToEnd ();
				err += "\n" + proc.StandardError.ReadToEnd ();

				if (File.Exists (pfile))
				{
					if (proc.ExitCode == 1) {
						string fn = fd.Name + prot + "Proxy.cs";
						fn = Path.Combine (GetErrorPath(), fn);
						CreateFolderForFile (fn);
						File.Move (pfile, fn);
						
						StreamWriter sw = new StreamWriter (fn, true);
						sw.WriteLine ();
						sw.WriteLine ("// " + fd.Wsdl);
						sw.WriteLine ();
						sw.Close ();
						
					}
					else
						File.Delete (pfile);
				}
				
				WriteError (errdoc, ns, "Errors found while generating " + prot + " proxy for WSDL: " + wsdl, err);
			}
			else
			{
				if (File.Exists (pfile)) {
					Console.WriteLine ("OK");
					proxies.Add (pfile);
				}
				else {
					Console.WriteLine ("FAIL");
					string err = proc.StandardOutput.ReadToEnd ();
					err += "\n" + proc.StandardError.ReadToEnd ();
					WriteError (errdoc, ns, "Errors found while generating " + prot + " proxy for WSDL: " + wsdl, err);
				}
			}
		}
	}
开发者ID:nobled,项目名称:mono,代码行数:84,代码来源:wstest.cs

示例13: GenericProcessor

    private Status GenericProcessor(GameRecord record, Task currentTask, Task nextTask, string command, int runTimeout = -1, bool addRetry = true)
    {
        string msg;
        Status returnStatus = Status.NA;
        if (activeCliProcess == null)
        {
            stateQueueMutex.WaitOne();
            stateQueue.Enqueue(new Tuple<GameRecord, Task, Status>(record, currentTask, Status.Wait));
            stateQueueMutex.ReleaseMutex();

            // split
            string exepart = command.Substring(0, command.IndexOf(".exe\"")+5);
            string argpart = command.Substring(command.IndexOf(".exe\"")+5);

            activeCliProcess = new Process();
            ProcessStartInfo startInfo = new ProcessStartInfo();
            startInfo.WindowStyle = ProcessWindowStyle.Hidden;

            startInfo.FileName = exepart;
            startInfo.Arguments = argpart;

            /*
            startInfo.FileName = "cmd.exe";
            startInfo.Arguments = "/C "+command;
            */

            startInfo.CreateNoWindow = true;
            startInfo.UseShellExecute = false;
            startInfo.RedirectStandardError = true;
            startInfo.RedirectStandardOutput = true;

            activeCliProcess.StartInfo = startInfo;
            activeCliProcess.Start();

            //messageQueueMutex.WaitOne();
            //messageQueue.Enqueue("Running command " + command);
            //messageQueueMutex.ReleaseMutex();

            if (runTimeout == -1)
            {
                if (!activeCliProcess.WaitForExit(MAX_TIMEOUT))
                {
                    activeCliProcess.Kill();
                    stateQueueMutex.WaitOne();
                    msg = "Process timeout: killed.";
                    messageQueue.Enqueue(msg);
                    detailedMessages[record.Author].Add(msg);
                    stateQueueMutex.ReleaseMutex();
                    Thread.Sleep(200);
                }
            }
            else
            {
                activeCliProcess.WaitForExit(runTimeout);
            }
        }
        if (activeCliProcess.HasExited)
        {

            // THIS is probably CMD.exe exitcode
            if (activeCliProcess.ExitCode == 0)
            {
                stateQueueMutex.WaitOne();
                msg = "Process exited with CODE 0.";
                messageQueue.Enqueue(msg);
                detailedMessages[record.Author].Add("\n"+msg);

                StreamReader sr = activeCliProcess.StandardOutput;
                while (!sr.EndOfStream)
                {
                    String s = sr.ReadLine();
                    if (s != "")
                    {
                        Trace.WriteLine(s);
                        detailedMessages[record.Author].Add(s);
                    }
                }

                stateQueue.Enqueue(new Tuple<GameRecord, Task, Status>(record, currentTask, Status.OK));
                returnStatus = Status.OK;

                stateQueueMutex.ReleaseMutex();

                // TODO: Check if it was successfull, //  update light bulb state and
                if (nextTask != Task.None)
                    taskQueue.Insert(0, new Tuple<GameRecord, Task>(record, nextTask));
            }
            else
            {
                stateQueueMutex.WaitOne();
                msg = "Process exited with CODE 1.";
                messageQueue.Enqueue(msg);
                detailedMessages[record.Author].Add("\n" + msg);

                StreamReader sro = activeCliProcess.StandardOutput;
                while (!sro.EndOfStream)
                {
                    String s = sro.ReadLine();
                    if (s != "")
                    {
//.........这里部分代码省略.........
开发者ID:juherask,项目名称:tarkistaOppilaidenJypelit,代码行数:101,代码来源:TarkistaOppilaidenPelit.cs

示例14: Execute

    public override IEnumerator Execute(UTContext context)
    {
        var theProjectPath = projectPath.EvaluateIn (context);
        if (!Directory.Exists (theProjectPath)) {
            throw new UTFailBuildException ("Project path " + theProjectPath + " does not exist.", this);
        }

        if (UTFileUtils.IsBelow (UTFileUtils.ProjectRoot, theProjectPath)) {
            throw new UTFailBuildException ("You cannot run uTomate externally on the current project. Use the Sub-Plan node if you want to run a plan as part of a plan.", this);
        }

        var thePlanName = planName.EvaluateIn (context);
        var theDebugMode = debugMode.EvaluateIn (context);

        var theProperties = EvaluateAll (properties, context);

        StringBuilder sb = new StringBuilder ();
        foreach (var prop in theProperties) {
            sb.Append (" -prop ").Append (UTExecutableParam.Quote (prop));
        }

        Process process = new Process ();
        process.StartInfo.FileName = UTils.GetEditorExecutable ();
        process.StartInfo.Arguments = "-projectPath " + UTExecutableParam.Quote (theProjectPath) +
            " -executeMethod UTExternalRunner.RunPlan -plan " + UTExecutableParam.Quote (thePlanName) +
                " -debugMode " + theDebugMode + sb.ToString ();
        if (UTPreferences.DebugMode) {
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.UseShellExecute = false;
            process.OutputDataReceived += (sender, args) => UDebug.Log ("[Unity]" + args.Data);
            UDebug.Log ("Executing: " + process.StartInfo.FileName + " with arguments " + process.StartInfo.Arguments);
        }

        try {
            if (!process.Start ()) {
                throw new UTFailBuildException ("Unable to start Unity3D.", this);
            }
            if (UTPreferences.DebugMode) {
                process.BeginOutputReadLine ();
            }
        } catch (Win32Exception e) {
            throw new UTFailBuildException ("Unable to start process " + e.Message, this);
        }
        do {
            yield return "";
            if (context.CancelRequested && !process.HasExited) {
                process.Kill ();
                break;
            }

        } while(!process.HasExited);

        if (!context.CancelRequested && failOnError.EvaluateIn (context)) {
            if (process.ExitCode != 0) {
                throw new UTFailBuildException ("Plan " + thePlanName + " failed or was cancelled.", this);
            }
        }
    }
开发者ID:realshyfox,项目名称:PlayMakerCustomActions_U3,代码行数:58,代码来源:UTRunUTomateInExternalProjectAction.cs

示例15: InstallSonarQubeNTService

    /// <summary>
    /// Installs SonarQube NT service.
    /// </summary>
    public static bool InstallSonarQubeNTService(Session session)
    {
        bool result = true;
        Process installServiceProcess = new Process();
        JavaVersionInformation information = JavaVersionHelper.GetJavaVersionInformation();

        installServiceProcess.StartInfo.FileName = session.Property("INSTALLDIR") +
                                                   string.Format(@"\{0}\bin\windows-x86-{1}\InstallNTService.bat",
                                                                 BootstrapperConstants.SonarQubeProductName,
                                                                 (int)information.Architecture);

        installServiceProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
        installServiceProcess.StartInfo.CreateNoWindow = true;
        installServiceProcess.StartInfo.UseShellExecute = false;
        installServiceProcess.Start();

        // We have to set the wait time for this process as in case of failures, batch file
        // prompts user about the failure and waits for the user response (key hit) to exit.
        installServiceProcess.WaitForExit(ProcessExitWaitTime);

        // This needs to be done as this batch file can wait for standard input in case of failure.
        // We nicely kill this process ourselves in this case to not stop the setup from progressing.
        if (!installServiceProcess.HasExited)
        {
            installServiceProcess.Kill();
        }

        if (installServiceProcess.ExitCode != 0)
        {
            session.Log("[InstallSonarQubeNTService] Process exited with {0}", installServiceProcess.ExitCode);
            result = false;
        }

        return result;
    }
开发者ID:SonarQubeCommunity,项目名称:sonarqube-windows-installer,代码行数:38,代码来源:Program.cs


注:本文中的Process.Kill方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。