void Launch(string command, int seq, dynamic args) { // 런치 전에 디버기가 접속할 수 있게 포트를 먼저 열어야 한다. var listener = PrepareForDebuggee(command, seq, args); string gprojPath = args.gprojPath; if (gprojPath == null) { //-------------------------------- // validate argument 'executable' var runtimeExecutable = (string)args.executable; if (runtimeExecutable == null) { runtimeExecutable = ""; } runtimeExecutable = runtimeExecutable.Trim(); if (runtimeExecutable.Length == 0) { SendErrorResponse(command, seq, 3005, "Property 'executable' is empty."); return; } var runtimeExecutableFull = GetFullPath(runtimeExecutable); if (runtimeExecutableFull == null) { SendErrorResponse(command, seq, 3006, "Runtime executable '{path}' does not exist.", new { path = runtimeExecutable }); return; } //-------------------------------- if (!ReadBasicConfiguration(command, seq, args)) { return; } //-------------------------------- var arguments = (string)args.arguments; if (arguments == null) { arguments = ""; } // validate argument 'env' Dictionary <string, string> env = null; var environmentVariables = args.env; if (environmentVariables != null) { env = new Dictionary <string, string>(); foreach (var entry in environmentVariables) { env.Add((string)entry.Name, entry.Value.ToString()); } if (env.Count == 0) { env = null; } } process = new Process(); process.StartInfo.CreateNoWindow = false; process.StartInfo.WindowStyle = ProcessWindowStyle.Normal; process.StartInfo.UseShellExecute = true; process.StartInfo.WorkingDirectory = workingDirectory; process.StartInfo.FileName = runtimeExecutableFull; process.StartInfo.Arguments = arguments; process.EnableRaisingEvents = true; process.Exited += (object sender, EventArgs e) => { lock (this) { toVSCode.SendMessage(new TerminatedEvent()); } }; if (env != null) { foreach (var entry in env) { System.Environment.SetEnvironmentVariable(entry.Key, entry.Value); } } var cmd = string.Format("{0} {1}\n", runtimeExecutableFull, arguments); toVSCode.SendOutput("console", cmd); try { process.Start(); } catch (Exception e) { SendErrorResponse(command, seq, 3012, "Can't launch terminal ({reason}).", new { reason = e.Message }); return; } } else { giderosRemoteController = new RemoteController(); var connectStartedAt = DateTime.Now; bool alreadyLaunched = false; while (!giderosRemoteController.TryStart("127.0.0.1", 15000, gprojPath, this)) { if (DateTime.Now - connectStartedAt > TimeSpan.FromSeconds(10)) { SendErrorResponse(command, seq, 3012, "Can't connect to GiderosPlayer.", new { }); return; } else if (alreadyLaunched) { System.Threading.Thread.Sleep(100); } else { try { var giderosPath = (string)args.giderosPath; process = new Process(); process.StartInfo.UseShellExecute = true; process.StartInfo.CreateNoWindow = true; process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; process.StartInfo.WorkingDirectory = giderosPath; // I don't know why this fix keeps GiderosPlayer.exe running // after DebugAdapter stops. // And I don't want to know.. process.StartInfo.FileName = "cmd.exe"; process.StartInfo.Arguments = "/c \"start GiderosPlayer.exe\""; process.Start(); Program.WaitingUI.SetLabelText( "Launching " + process.StartInfo.FileName + " " + process.StartInfo.Arguments + "..."); } catch (Exception e) { SendErrorResponse(command, seq, 3012, "Can't launch GiderosPlayer ({reason}).", new { reason = e.Message }); return; } alreadyLaunched = true; } } new System.Threading.Thread(giderosRemoteController.ReadLoop).Start(); } AcceptDebuggee(command, seq, args, listener); }
void Launch(string command, int seq, dynamic args) { var arguments = (string)args.arguments; if (arguments == null) { arguments = ""; } // working directory string workingDirectory = (string)args.workingDirectory; if (workingDirectory == null) { workingDirectory = ""; } workingDirectory = workingDirectory.Trim(); if (workingDirectory.Length == 0) { SendErrorResponse(command, seq, 3003, "Property 'workingDirectory' is empty."); return; } if (!Directory.Exists(workingDirectory)) { SendErrorResponse(command, seq, 3004, "Working directory '{path}' does not exist.", new { path = workingDirectory }); return; } // executable var runtimeExecutable = (string)args.executable; if (runtimeExecutable == null) { runtimeExecutable = ""; } runtimeExecutable = runtimeExecutable.Trim(); if (runtimeExecutable.Length == 0) { SendErrorResponse(command, seq, 3005, "Property 'executable' is empty."); return; } var runtimeExecutableFull = GetFullPath(runtimeExecutable); if (runtimeExecutableFull == null) { SendErrorResponse(command, seq, 3006, "Runtime executable '{path}' does not exist.", new { path = runtimeExecutable }); return; } // validate argument 'env' Dictionary <string, string> env = null; var environmentVariables = args.env; if (environmentVariables != null) { env = new Dictionary <string, string>(); foreach (var entry in environmentVariables) { env.Add((string)entry.Name, entry.Value.ToString()); } if (env.Count == 0) { env = null; } } process = new Process(); process.StartInfo.CreateNoWindow = false; process.StartInfo.WindowStyle = ProcessWindowStyle.Normal; process.StartInfo.UseShellExecute = true; process.StartInfo.WorkingDirectory = workingDirectory; process.StartInfo.FileName = runtimeExecutableFull; process.StartInfo.Arguments = arguments; process.EnableRaisingEvents = true; process.Exited += (object sender, EventArgs e) => { lock (this) { toVSCode.SendMessage(new TerminatedEvent()); } }; if (env != null) { foreach (var entry in env) { System.Environment.SetEnvironmentVariable(entry.Key, entry.Value); } } var cmd = string.Format("{0} {1}\n", runtimeExecutableFull, arguments); toVSCode.SendOutput("console", cmd); try { process.Start(); } catch (Exception e) { SendErrorResponse(command, seq, 3012, "Can't launch terminal ({reason}).", new { reason = e.Message }); return; } Attach(command, seq, args); }