public static Process StartWithoutShellExecute(this IExternalApplication app, IEnumerable <string> args) { return(app.Start(new ProcessStartInfo { Arguments = args.Select(a => "\"" + a + "\"").Join(" "), UseShellExecute = false, RedirectStandardInput = true, RedirectStandardOutput = true, RedirectStandardError = true, CreateNoWindow = true })); }
public static UnoHostProcess Spawn(AbsoluteFilePath assembly, IObservable <IBinaryMessage> messagesToUnoHost, AbsoluteFilePath userDataPath, IEnumerable <string> moreArgs) { if (Application == null) { throw new InvalidOperationException("UnoHostProcess.Application has not been initialized"); } var args = new UnoHostArgs { AssemblyPath = assembly, OutputPipe = PipeName.New(), InputPipe = PipeName.New(), UserDataPath = userDataPath, }; var disp = args.InputPipe.BeginWritingMessages("UnoHost", ex => Console.WriteLine("Designer failed to write message to UnoHost: " + ex), messagesToUnoHost); return(new UnoHostProcess { Messages = args.OutputPipe.ReadMessages("UnoHost"), Process = Observable.Start(() => Application.Start(args.Serialize().Concat(moreArgs))), Disposables = Disposable.Combine(disp) }); }
public override void Run(string[] args, CancellationToken ct) { _report.Info("Building with arguments '" + string.Join(" ", args) + "'"); try { using (var client = _daemonSpawner.ConnectOrSpawn( identifier: "Builder", timeout: TimeSpan.FromMinutes(1))) { Func <string, Optional <string> > parseNameArg = s => TryParseArg("n", "name", s); Func <string, Optional <string> > parseTargetArg = s => TryParseArg("t", "target", s); Func <Optional <string>, BuildTarget> targetToTargetEnum = s => { if (!s.HasValue) { return(BuildTarget.Unknown); } try { return((BuildTarget)Enum.Parse(typeof(BuildTarget), s.Value)); } catch (ArgumentException) { return(BuildTarget.Unknown); } }; var nameArgs = args.Select(parseNameArg).NotNone(); var nameArg = nameArgs.FirstOrNone(); var targetArgs = args.Select(parseTargetArg).NotNone(); var targetArg = targetArgs.FirstOrNone(); args = args.Where(s => !parseNameArg(s).HasValue).ToArray(); //uno does not accept name arg so strip it var buildId = Guid.NewGuid(); //_report.Info(string.Format("Calling '{0} {1}', with buildId '{2}'", startInfo.FileName, startInfo.Arguments, buildId)); var maybeFileOrProject = args .FirstOrNone(a => !a.StartsWith("-")) .Select(_fileSystem.ResolveAbsolutePath); var projPath = _projectDetector.GetCurrentProject(maybeFileOrProject); var target = targetToTargetEnum(targetArg); client.Broadcast( new BuildStartedData { BuildId = buildId, Target = target, BuildType = BuildTypeData.FullCompile, ProjectId = ProjectIdComputer.IdFor(projPath), ProjectPath = projPath.NativePath, BuildTag = nameArg.Or("") }); var outputData = new Subject <string>(); var errorData = new Subject <string>(); // ReSharper disable once AccessToDisposedClosure using (Observable.Merge(outputData, errorData).Subscribe(line => BroadCastBuildLog(line, client, buildId))) using (outputData.Select(line => line + "\n").Subscribe(_outWriter.Write)) using (errorData.Select(line => line + "\n").Subscribe(_errorWriter.Write)) { Process proc; try { proc = _uno.Start(new ProcessStartInfo { WindowStyle = ProcessWindowStyle.Hidden, Arguments = "build " + args.Select( s => { if (s.EndsWith("\\")) { return("\"" + s + " \""); } else { return("\"" + s + "\""); } }).Join(" "), RedirectStandardOutput = true, RedirectStandardError = true, UseShellExecute = false }); } catch (Exception e) { throw new FailedToStartBuild(e); } proc.ConsumeOutAndErr(outputData, errorData).Wait(); proc.WaitForExit(); var status = proc.ExitCode == 0 ? BuildStatus.Success : BuildStatus.Error; client.Broadcast( new BuildEndedData { BuildId = buildId, Status = status }); if (status == BuildStatus.Success) { _report.Info("Build " + buildId + " succeeded"); } else { _report.Error("Build " + buildId + " failed"); throw new UserCodeContainsErrors(); } } } } catch (DaemonException e) { throw new ExitWithError(e.Message); } catch (InvalidPath e) { throw new ExitWithError(e.Message); } catch (SecurityException e) { throw new ExitWithError(e.Message); } catch (ProjectNotFound e) { throw new ExitWithError(e.Message); } catch (FailedToStartBuild e) { throw new ExitWithError(e.Message); } catch (UserCodeContainsErrors e) { throw new ExitWithError(e.Message); } }
public static Process Start(this IExternalApplication app, IEnumerable <string> args) { return(app.Start(new ProcessStartInfo { Arguments = args.Select(a => "\"" + a + "\"").Join(" ") })); }