public static NodeProcess Start(ProcessStartInfo psi, bool waitOnAbnormal, bool waitOnNormal) { var res = new NodeProcess(psi, waitOnAbnormal, waitOnNormal, false); res.Start(); return(res); }
/// <summary> /// Terminates Node.js process. /// </summary> public void Terminate(bool killProcess = true) { lock (this) { // Disconnect _connection.Close(); // Fall back to using -1 for exit code if we cannot obtain one from the process // This is the normal case for attach where there is no process to interrogate int exitCode = -1; if (_process != null) { // Cleanup process Debug.Assert(!_attached); try { if (killProcess && !_process.HasExited) { _process.Kill(); } else { exitCode = _process.ExitCode; } } catch (InvalidOperationException) { } catch (Win32Exception) { } _process.Dispose(); _process = null; } else { // Avoid multiple events fired if multiple calls to Terminate() if (!_attached) { return; } _attached = false; } // Fire event EventHandler<ProcessExitedEventArgs> exited = ProcessExited; if (exited != null) { exited(this, new ProcessExitedEventArgs(exitCode)); } } }
public NodeDebugger( string exe, string script, string dir, string env, string interpreterOptions, NodeDebugOptions debugOptions, ushort? debuggerPort = null, bool createNodeWindow = true) : this() { // Select debugger port for a local connection ushort debuggerPortOrDefault = NodejsConstants.DefaultDebuggerPort; if (debuggerPort != null) { debuggerPortOrDefault = debuggerPort.Value; } else { List<int> activeConnections = (from listener in IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpListeners() select listener.Port).ToList(); if (activeConnections.Contains(debuggerPortOrDefault)) { debuggerPortOrDefault = (ushort)Enumerable.Range(new Random().Next(5859, 6000), 60000).Except(activeConnections).First(); } } _debuggerEndpointUri = new UriBuilder { Scheme = "tcp", Host = "localhost", Port = debuggerPortOrDefault }.Uri; // Node usage: node [options] [ -e script | script.js ] [arguments] string allArgs = String.Format( "--debug-brk={0} --nolazy {1} {2}", debuggerPortOrDefault, interpreterOptions, script ); var psi = new ProcessStartInfo(exe, allArgs) { CreateNoWindow = !createNodeWindow, WorkingDirectory = dir, UseShellExecute = false }; if (env != null) { string[] envValues = env.Split('\0'); foreach (string curValue in envValues) { string[] nameValue = curValue.Split(new[] { '=' }, 2); if (nameValue.Length == 2 && !String.IsNullOrWhiteSpace(nameValue[0])) { psi.EnvironmentVariables[nameValue[0]] = nameValue[1]; } } } _process = new NodeProcess( psi, debugOptions.HasFlag(NodeDebugOptions.WaitOnAbnormalExit), debugOptions.HasFlag(NodeDebugOptions.WaitOnNormalExit), true); }
public static NodeProcess Start(ProcessStartInfo psi, bool waitOnAbnormal, bool waitOnNormal) { var res = new NodeProcess(psi, waitOnAbnormal, waitOnNormal, false); res.Start(); return res; }