public bool startJavaShell(DataReceivedEventHandler dataReceivedCallBack, string extraExecutionArguments) { try { classPath = getListOfCurrentJarStubsForClassPath(classPath); var executionArguments = string.Format(ikvm.IKVMExecution_Script, classPath, classToExecute, extraExecutionArguments); if (extraExecutionArguments!="") executionArguments += " " + extraExecutionArguments; var executionWorkingDirectory = PublicDI.config.CurrentExecutableDirectory; dataReceived = null; inputStream = null; IKVMProcess = null; IKVMProcess = Processes.startProcessAndRedirectIO(ikvm.IKVMExecutable, executionArguments, ref inputStream, dataReceivedCallBack, dataReceivedCallBack); if (inputStream != null) return true; "in startJavaShell , IKVMProcess.inputStream == null".error(); } catch (Exception ex) { ex.log(); } return false; }
public CGitAsynchFomr() { syncContext = SynchronizationContext.Current; ProcessReceiveData = new DataReceivedEventHandler(GitProcessReceiveData); ProcessAbort = new ExitProcessHandler(GitProcessExit); ProcessErrorData = new DataReceivedEventHandler(GitProcessErrorData); }
public MainForm() { InitializeComponent(); OutBuffer = new StringBuilder(LogSize); dEthminerDataRecieved = EthminerDataReceived; }
public static Process CheckSshKey(string szSSHURL, DataReceivedEventHandler AppHandleOutput, DataReceivedEventHandler AppHandleError, EventHandler AppHandleAbort) { szSSHURL=szSSHURL.TrimEnd(':'); string szPort = null; string szUrl = szSSHURL; int nPos = szSSHURL.LastIndexOf(":"); if (nPos >= 0) { szPort = szSSHURL.Substring(nPos + 1, szSSHURL.Length - nPos - 1); szUrl = szSSHURL.Substring(0, nPos ); } string szExeArgument; if(string.IsNullOrEmpty(szPort.Trim())) { szExeArgument = string.Format("-T \"{0}\"", szUrl); ; } else { szExeArgument = string.Format("-T -p {0} \"{1}\"", szPort, szUrl); ; } string.Format("-T -p 29418 [email protected] \"{0}\"", szSSHURL); return CGitSourceConfig.m_objGitSrcModule.RunCommonCmdAsynch(@"ssh", szExeArgument, AppHandleOutput, AppHandleError, AppHandleAbort); }
public static int ExecuteAndWaitForExit(string filename, string arguments, string workingDirectory, TextWriter outputData, TextWriter outputError, int? timeout) { var entrance = new object(); DataReceivedEventHandler d1 = null; if (outputData != null) { d1 = new DataReceivedEventHandler(delegate(object x1, DataReceivedEventArgs e) { lock (entrance) { outputData.Write(e.Data); } }); } DataReceivedEventHandler d2 = null; if (outputError != null) { d2 = new DataReceivedEventHandler(delegate(object x1, DataReceivedEventArgs e) { lock (entrance) { outputError.Write(e.Data); } }); } return ExecuteAndWaitForExit(filename, arguments, workingDirectory, d1, d2, null, null, timeout); }
void OnDataReceived(DataReceivedEventHandler handler, DataReceivedEventArgs e) { if (handler != null) { handler(this, e); } }
private Task StartLivestreamer(string inputUrl, DataReceivedEventHandler onData) => Task.Run(() => { Process livestreamer = new Process { StartInfo = { FileName = Config.LivestreamerDir, Arguments = $"--stream-url {inputUrl} best", UseShellExecute = false, RedirectStandardOutput = true, CreateNoWindow = true }, EnableRaisingEvents = true }; livestreamer.OutputDataReceived += onData; if (!livestreamer.Start()) Logger.FormattedWrite(typeof (TrackData).Name, "Failed starting livestreamer.", ConsoleColor.Red); livestreamer.BeginOutputReadLine(); livestreamer.WaitForExit(); livestreamer.OutputDataReceived -= onData; });
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(); }
public SyncCmd(DataReceivedEventHandler hander = null) { p.OutputDataReceived += new DataReceivedEventHandler(p_OutputDataReceived); p.ErrorDataReceived += hander ?? new DataReceivedEventHandler(p_ErrorDataReceived); p.StartInfo.WorkingDirectory = System.Environment.CurrentDirectory; //设定程序名 p.StartInfo.FileName = "cmd.exe"; //关闭Shell的使用 p.StartInfo.UseShellExecute = false; //重定向标准输入 p.StartInfo.RedirectStandardInput = true; //重定向标准输出 p.StartInfo.RedirectStandardOutput = true; //重定向错误输出 p.StartInfo.RedirectStandardError = true; //设置不显示窗口 p.StartInfo.CreateNoWindow = true; }
public static ShellProcess Run(String cmd, String args, DataReceivedEventHandler outputDataReceivedEventHandler, DataReceivedEventHandler errorDataReceivedEventHandler) { return RunShellProcess(new ShellProcess( cmd, args, outputDataReceivedEventHandler, errorDataReceivedEventHandler)); }
public override void RunSimulation(DataReceivedEventHandler outputDataReceived, DataReceivedEventHandler errorDataReceived, EventHandler exited) { CreateCtlFile(); CreateShellScript(); ProcessStartInfo pInfo = new ProcessStartInfo(); pInfo.FileName = CygwinDirectoryPath + "\\" + CygwinExecutionFilePath; pInfo.UseShellExecute = false; pInfo.CreateNoWindow = true; pInfo.RedirectStandardInput = true; pInfo.RedirectStandardOutput = true; pInfo.RedirectStandardError = true; CygwinProcess = new Process(); CygwinProcess.StartInfo = pInfo; CygwinProcess.OutputDataReceived += outputDataReceived; CygwinProcess.ErrorDataReceived += errorDataReceived; CygwinProcess.Exited += exited ?? new EventHandler( (object o, EventArgs e) => { } ); CygwinProcess.Start(); CygwinProcess.EnableRaisingEvents = true; CygwinProcess.BeginOutputReadLine(); CygwinProcess.BeginErrorReadLine(); CygwinProcess.StandardInput.WriteLine( @"cd " + WorkingDirectoryPathInCygwin ); CygwinProcess.StandardInput.WriteLine( @"./simulation.sh" ); //CygwinProcess.StandardInput.WriteLine( @"" ); //CygwinProcess.StandardInput.WriteLine( @"" ); //CygwinProcess.StandardInput.WriteLine( @"" ); CygwinProcess.StandardInput.WriteLine( @"exit" ); }
// if we pass a callback for logging we need to start a IKVM shell public Process executeJavaFile(string fileToExecute, DataReceivedEventHandler dataReceivedCallBack) { var IKVMShell = new JavaShell(ikvm); IKVMShell.compileJavaFile(fileToExecute); IKVMShell.executeClassFile(dataReceivedCallBack); //IKVMShell.startJavaShell(dataReceivedCallBack, fileToExecute); return IKVMShell.IKVMProcess; }
public Process executeAppScanDEScan(string targetFolder,string tempAppScanWorkingDirectory, DataReceivedEventHandler onAppScanLogEvent) { var executable = "java.exe"; var executableParams = appScanDECommandLineParams1 + appScanDECommandLineParams2 + appScanDECommandLineParams3 + appScanDECommandLineParams4 + appScanDECommandLineParams5 + appScanDECommandLineParams6 + " \"" + targetFolder + "\" \"" + tempAppScanWorkingDirectory + "\""; return Processes.startProcessAsConsoleApplication(executable, executableParams, onAppScanLogEvent); }
public CGitAsynchControl() { //callback initialize syncContext = SynchronizationContext.Current; ProcessReceiveData = new DataReceivedEventHandler(GitProcessReceiveData); ProcessAbort = new ExitProcessHandler(GitProcessExit); ProcessErrorData = new DataReceivedEventHandler(GitProcessErrorData); m_WaitForm = null; }
//asynch operation public static Process UpLoadBranchAsynch(string szRemoteRepoName, string szBranch,DataReceivedEventHandler AppHandleOutput, DataReceivedEventHandler AppHandleError, EventHandler AppHandleAbort) { if (string.IsNullOrEmpty(szRemoteRepoName) || string.IsNullOrEmpty(szBranch)) { return null; } string szExeCmd = string.Format("push {0} {1}", szRemoteRepoName, szBranch); return CGitSourceConfig.m_objGitSrcModule.RunGitCmdAsynch(szExeCmd, AppHandleOutput, AppHandleError, AppHandleAbort); }
public static Process runAsynch(string szRepositoryUrl, string szWorkingDir,DataReceivedEventHandler AppHandleOutput, DataReceivedEventHandler AppHandleError, EventHandler AppHandleAbort) { if (string.IsNullOrEmpty(szWorkingDir)||string.IsNullOrEmpty(szRepositoryUrl)) { return null ; } string szArgument=GetArgument(szRepositoryUrl,szWorkingDir,null,0); return CGitSourceConfig.m_objGitSrcModule.RunGitCmdAsynch(szArgument,AppHandleOutput,AppHandleError,AppHandleAbort); }
public ShellProcess(String cmd, String args, DataReceivedEventHandler outputDataReceivedEventHandler) { ProcStartInfo = new ProcessStartInfo(cmd, args); ProcStartInfo.RedirectStandardError = true; ProcStartInfo.RedirectStandardOutput = true; ProcStartInfo.UseShellExecute = false; ProcStartInfo.CreateNoWindow = true; m_OutputDataReceivedEventHandler = outputDataReceivedEventHandler; m_ErrorDataReceivedEventHandler = null; }
// Методы #region Методы public static void InitializeProcessManager(MainWindow mainWindow) { m_MainWindow = mainWindow; m_TaskCounter = 0; m_Tasks = null; m_CurrentTask = null; m_DataReceivedHandler = null; m_RunMode = RunMode.All; m_IsCurrentlySomeTaskRunning = false; }
public bool Execute(CancellationToken cancellationToken, string workingDirectory, string commandPath, string commandArguments, out string output) { UnableToExecuteCommand = false; Output = new StringBuilder(); DataReceivedEventHandlerOutput = new DataReceivedEventHandler(OnOutputDataReceived); DataReceivedEventHandlerError = new DataReceivedEventHandler(OnErrorDataReceived); var processCommand = new Process(); try { processCommand.StartInfo.WorkingDirectory = workingDirectory; processCommand.StartInfo.FileName = commandPath; processCommand.StartInfo.Arguments = commandArguments; processCommand.StartInfo.UseShellExecute = false; processCommand.StartInfo.CreateNoWindow = true; processCommand.StartInfo.RedirectStandardError = true; processCommand.StartInfo.RedirectStandardOutput = true; processCommand.OutputDataReceived += DataReceivedEventHandlerOutput; processCommand.ErrorDataReceived += DataReceivedEventHandlerError; Output.Append(commandPath + " "); Output.AppendLine(commandArguments); _logger.Info(string.Format(Properties.Resource.InfoMessageCommandLineStarted, commandPath, commandArguments)); if (!cancellationToken.IsCancellationRequested) { cancellationToken.Register(() => processCommand.Kill()); processCommand.Start(); processCommand.BeginOutputReadLine(); processCommand.BeginErrorReadLine(); processCommand.WaitForExit(); } cancellationToken.ThrowIfCancellationRequested(); _logger.Info(string.Format(Properties.Resource.InfoMessageCommandLineCompleted, commandPath, commandArguments)); } finally { processCommand.OutputDataReceived -= DataReceivedEventHandlerOutput; processCommand.ErrorDataReceived -= DataReceivedEventHandlerError; processCommand.Close(); DataReceivedEventHandlerOutput = null; DataReceivedEventHandlerError = null; } output = Output.ToString(); return !UnableToExecuteCommand; }
public async Task Start(string arguments, Action<string> processData, CancellationTokenWrapper token) { var tcs = new TaskCompletionSource<object>(); _act = (s, e) => { _output.AppendLine(e.Data); try { processData(e.Data); } catch (Exception ex) { tcs.TrySetException(ex); } }; var process = new Process(); process.Exited += (s, e) => ExitedMethod((Process)s, tcs); process.StartInfo = CreateStartInfo(arguments); process.EnableRaisingEvents = true; process.ErrorDataReceived += _act; process.OutputDataReceived += _act; _output.Clear(); try { process.Start(); process.BeginErrorReadLine(); process.BeginOutputReadLine(); token.Register(() => tcs.TrySetCanceled()); } catch (Exception ex) { tcs.TrySetException(ex); } try { await tcs.Task; } finally { TryKillProcess(process); process.Dispose(); } }
//asynch operation public static Process PullBranchAsynch(string szRemoteRepoName,string szRemoteBranch,bool bIsRebaseMode,DataReceivedEventHandler AppHandleOutput, DataReceivedEventHandler AppHandleError, EventHandler AppHandleAbort) { if (string.IsNullOrEmpty(szRemoteRepoName) || string.IsNullOrEmpty(szRemoteBranch)) { return null; } string szExeCmd =string.Empty; if (bIsRebaseMode == false) szExeCmd= string.Format("pull -v --progress {0} {1}", szRemoteRepoName,szRemoteBranch); else szExeCmd = string.Format("pull -v --progress --rebase {0} {1}", szRemoteRepoName, szRemoteBranch); return CGitSourceConfig.m_objGitSrcModule.RunGitCmdAsynch(szExeCmd, AppHandleOutput, AppHandleError, AppHandleAbort); }
public void Start(String ScriptPath, DataReceivedEventHandler outoutData, DataReceivedEventHandler errorData) { if (!App.WebCrawlerConnected && !String.IsNullOrWhiteSpace(ScriptPath)) { NodeInfo.Arguments = Path.GetFileName(ScriptPath); NodeInfo.WorkingDirectory = Path.GetDirectoryName(ScriptPath); node = Process.Start(NodeInfo); node.BeginOutputReadLine(); node.BeginErrorReadLine(); node.OutputDataReceived += outoutData; node.ErrorDataReceived += errorData; } }
public static Thread GetAllCommitsBySybcThread(DataReceivedEventHandler AppHandleOutput, DataReceivedEventHandler AppHandleError, EventHandler AppHandleAbort) { string szArgument = @"log -z --pretty=format:"; szArgument = szArgument + @"((__VALID_ITEM_0__))"; //@"((__VALID_COMMIT_ITEM__))"; szArgument += @"%H((__VALID_ITEM_1__))" //@"%H((__VALID_HASH_ITEM__))" + @"%P((__VALID_ITEM_2__))" //@"%P((__VALID_PARENT_ITEM__))" + @"%T((__VALID_ITEM_3__))"//@"%T((__VALID_TREE_ITEM__))" + @"%aN((__VALID_ITEM_4__))" //@"%aN((__VALID_AUTHOR_NAME_ITEM__))" + @"%aE((__VALID_ITEM_5__))" //@"%aE((__VALID_AUTHOR_EMAIL_ITEM__))" + @"%ai((__VALID_ITEM_6__))" //@"%ai((__VALID_AUTHOR_DATE_ITEM__))" + @"%cN((__VALID_ITEM_7__))" //@"%cN((__VALID_COMMITTER_NAME_ITEM__))" + @"%ci((__VALID_ITEM_8__))" // @"%ci((__VALID_COMMITTER_DATE_ITEM__))" + @"%e((__VALID_ITEM_9__))" // @"%e((__VALID_COMMITTER_ENCODE_ITEM__))" + @"%s((__VALID_ITEM_10__))" // @"%s((__VALID_COMMITTE_MESSAGE_ITEM__))" + @"%n"; szArgument = szArgument + @" --date-order --all --boundary"; return CGitSourceConfig.m_objGitSrcModule.RunGitCmdByThread(szArgument, AppHandleOutput, AppHandleError, AppHandleAbort); }
/// <summary> /// Initializes a new instance of the <see cref="TekkitServerProcess" /> class. /// </summary> /// <param name="eventLogSourceName">Name of the event log source.</param> internal TekkitServerProcess(string eventLogSourceName) { IsTekkitRunning = false; _eventLogSourceName = eventLogSourceName; // configure the start process information StartInfo.FileName = Properties.Settings.Default.JavaApp; StartInfo.Arguments = Properties.Settings.Default.JavaArgs; StartInfo.WorkingDirectory = Properties.Settings.Default.TekkitWorkingDirectory; StartInfo.UseShellExecute = false; StartInfo.RedirectStandardError = true; StartInfo.RedirectStandardInput = true; // setup events for the process ErrorDataReceived += new DataReceivedEventHandler(HandleTekkitServerErrorEvent); EnableRaisingEvents = true; Exited += new EventHandler(HandleTekkitServerExitedEvent); }
protected void RunExternalProcess(String Args, AsyncContext Context, out bool Cancelled, DataReceivedEventHandler DataHandler) { Cancelled = false; ProcessStartInfo StartInfo = new ProcessStartInfo(); StartInfo.CreateNoWindow = true; StartInfo.UseShellExecute = false; StartInfo.FileName = ProgramPath; StartInfo.WindowStyle = ProcessWindowStyle.Hidden; StartInfo.Arguments = Args.ToString(); StartInfo.RedirectStandardOutput = true; StartInfo.RedirectStandardError = true; try { Process ExtProcess = Process.Start(StartInfo); ExtProcess.OutputDataReceived += DataHandler; ExtProcess.ErrorDataReceived += DataHandler; // ExtProcess.ErrorDataReceived += new DataReceivedEventHandler(ExtProcess_ErrorDataReceived); ExtProcess.BeginErrorReadLine(); ExtProcess.BeginOutputReadLine(); while (!ExtProcess.HasExited) { if (Context.IsCancelling) { ExtProcess.Kill(); ExtProcess.WaitForExit(); Cancelled = true; return; } Thread.Sleep(250); } ExtProcess.WaitForExit(); } catch (Exception E) { throw E; // Console.WriteLine(E.Message); // Environment.Exit(0); } }
public string Run(string fileName, string arguments, out string errorMessage,DataReceivedEventHandler logHandler,DataReceivedEventHandler errorHandler) { errorMessage = ""; Process cmdLineProcess = new Process(); using (cmdLineProcess) { cmdLineProcess.StartInfo.FileName = fileName; cmdLineProcess.StartInfo.Arguments = arguments; cmdLineProcess.StartInfo.UseShellExecute = false; cmdLineProcess.StartInfo.CreateNoWindow = true; cmdLineProcess.StartInfo.WorkingDirectory = @"C:\Program Files (x86)\get_iplayer"; cmdLineProcess.StartInfo.RedirectStandardOutput = true; cmdLineProcess.StartInfo.RedirectStandardError = true; if (cmdLineProcess.Start()) { //cmdLineProcess.OutputDataReceived += new DataReceivedEventHandler(CmdOutputDataReceived); cmdLineProcess.OutputDataReceived += logHandler; cmdLineProcess.ErrorDataReceived += errorHandler; cmdLineProcess.BeginOutputReadLine(); //return ReadProcessOutput(cmdLineProcess, ref errorMessage, // fileName); return ""; } else { throw new CommandLineException(String.Format( "Could not start command line process: {0}", fileName)); /* Note: arguments aren't also shown in the * exception as they might contain privileged * information (such as passwords). */ } } }
public Process StartProcess( ProcessStartInfo processStartInfo, DataReceivedEventHandler outputDataReceived, DataReceivedEventHandler errorDataReceived) { Process executable = Process.Start(processStartInfo); if (outputDataReceived != null) { executable.OutputDataReceived += outputDataReceived; } if (errorDataReceived != null) { executable.ErrorDataReceived += errorDataReceived; } executable.BeginOutputReadLine(); executable.BeginErrorReadLine(); executable.WaitForExit(); return executable; }
/// <summary> /// Starts the process, and reads all output from the process /// </summary> /// <param name="processStartInfo">The process start info.</param> /// <param name="outputDataRecieved">The output data recieved.</param> /// <returns></returns> public static int StartProcess(this ProcessStartInfo processStartInfo, DataReceivedEventHandler outputDataRecieved) { processStartInfo.UseShellExecute = false; processStartInfo.RedirectStandardOutput = true; processStartInfo.RedirectStandardError = true; processStartInfo.CreateNoWindow = false; var process = new Process {StartInfo = processStartInfo}; if (outputDataRecieved != null) { process.OutputDataReceived += outputDataRecieved; process.ErrorDataReceived += outputDataRecieved; } process.Start(); process.BeginOutputReadLine(); process.BeginErrorReadLine(); process.WaitForExit(); return process.ExitCode; }
private void Run(string exe, string args, bool asAdmin, DataReceivedEventHandler d, DataReceivedEventHandler r) { var startInfo = new ProcessStartInfo() { CreateNoWindow = true, UseShellExecute = false, FileName = exe, Arguments = args, RedirectStandardError = true, RedirectStandardOutput = true, RedirectStandardInput = true }; if (asAdmin) { startInfo.Verb = "runas"; startInfo.UseShellExecute = true; startInfo.RedirectStandardError = false; startInfo.RedirectStandardOutput = false; startInfo.RedirectStandardInput = false; } logger.Debug("Running " + startInfo.FileName + " " + startInfo.Arguments); var proc = Process.Start(startInfo); if (!asAdmin) { proc.OutputDataReceived += d; proc.ErrorDataReceived += r; proc.BeginErrorReadLine(); proc.BeginOutputReadLine(); } proc.WaitForExit(); if (!asAdmin) { proc.OutputDataReceived -= d; proc.ErrorDataReceived -= r; } }
public bool startIronPythonShell(DataReceivedEventHandler dataReceivedCallBack, string executionArguments) { try { //var executionArguments = string.Format(IronPythonConfig.IronPythonJavaExecution_PythonShell, // IronPythonConfig._IronPythonRuntimeDir); dataReceived = null; inputStream = null; ironPythonProcess = null; ironPythonProcess = Processes.startProcessAndRedirectIO(IronPythonConfig.ironPythonExecutable, executionArguments, ref inputStream, dataReceivedCallBack, dataReceivedCallBack); if (inputStream != null) return true; DI.log.error("in startIronPythonShell , IronPythonProcess.inputStream == null"); } catch (Exception ex) { DI.log.ex(ex); } return false; }
private void StartQueuedDownloadIfExists() { if (this.paused) { return; } if (Monitor.TryEnter(this.changeDownloadLockObject)) { try { if (!this.Downloads.Where(d => d.DownloadStatus == DownloadStatus.Active).Any()) { TwitchVideoDownload download = this.Downloads.Where(d => d.DownloadStatus == DownloadStatus.Queued).FirstOrDefault(); if (download != null) { TwitchVideo video = download.Video; DownloadParameters downloadParams = download.DownloadParams; CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(); CancellationToken cancellationToken = cancellationTokenSource.Token; long completedChunkDownloads = 0; int maxConnectionCount = ServicePointManager.DefaultConnectionLimit; string urlId = video.Id.Substring(1); string quality = downloadParams.Resolution.VideoQuality.ToTwitchQuality(); string qualityFps = downloadParams.Resolution.ResolutionFps; string outputDir = Path.Combine(downloadsDir, urlId); string playlistFile = Path.Combine(outputDir, "vod.m3u8"); string ffmpegFile = Path.Combine(appDir, Environment.Is64BitOperatingSystem ? FFMPEG_EXE_X64 : FFMPEG_EXE_X86); string outputFile = downloadParams.Filename; Task downloadVideoTask = new Task(() => { download.Status = "Initializing"; download.AppendLog("Download task has been started!"); download.AppendLog(Environment.NewLine + Environment.NewLine + "VOD ID: " + urlId); download.AppendLog(Environment.NewLine + "Selected Quality: " + qualityFps); download.AppendLog(Environment.NewLine + "Download Url: " + video.Url.ToString()); download.AppendLog(Environment.NewLine + "Output File: " + outputFile); download.AppendLog(Environment.NewLine + "FFMPEG Path: " + ffmpegFile); download.AppendLog(Environment.NewLine + "Temporary Download Folder: " + outputDir); if (!Directory.Exists(outputDir)) { download.AppendLog(Environment.NewLine + Environment.NewLine + "Creating directory '" + outputDir + "'..."); FileSystem.CreateDirectory(outputDir); download.AppendLog(" done!"); } if (Directory.EnumerateFileSystemEntries(outputDir).Any()) { throw new ApplicationException("Temporary download directory '" + outputDir + "' is not empty!"); } using (WebClient webClient = new WebClient()) { download.AppendLog(Environment.NewLine + Environment.NewLine + "Retrieving access token and signature..."); string accessTokenStr = webClient.DownloadString(string.Format(accessTokenUrl, urlId)); download.AppendLog(" done!"); dynamic accessTokenJson = JsonConvert.DeserializeObject(accessTokenStr); string token = Uri.EscapeDataString(accessTokenJson.token.ToString()); string sig = accessTokenJson.sig.ToString(); download.AppendLog(Environment.NewLine + "Token: " + token); download.AppendLog(Environment.NewLine + "Signature: " + sig); cancellationToken.ThrowIfCancellationRequested(); download.AppendLog(Environment.NewLine + Environment.NewLine + "Retrieving m3u8 playlist urls for all VOD qualities..."); string allPlaylistsStr = webClient.DownloadString(string.Format(allPlaylistsUrl, urlId, sig, token)); download.AppendLog(" done!"); List <string> allPlaylistsList = allPlaylistsStr.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries).Where(s => !s.StartsWith("#")).ToList(); allPlaylistsList.ForEach(url => { download.AppendLog(Environment.NewLine + url); }); string playlistUrl = allPlaylistsList.Where(s => s.ToLowerInvariant().Contains(quality)).First(); download.AppendLog(Environment.NewLine + Environment.NewLine + "Playlist url for selected quality " + qualityFps + " is " + playlistUrl); cancellationToken.ThrowIfCancellationRequested(); download.AppendLog(Environment.NewLine + Environment.NewLine + "Retrieving list of video chunks..."); string playlistStr = webClient.DownloadString(playlistUrl); download.AppendLog(" done!"); List <string> playlistLines = playlistStr.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries).ToList(); List <string> webChunkList = playlistLines.Where(s => !s.StartsWith("#")).ToList(); string webChunkUrlPrefix = playlistUrl.Substring(0, playlistUrl.LastIndexOf("/") + 1); long webChunkCount = webChunkList.Count; download.AppendLog(Environment.NewLine + "Number of video chunks to download: " + webChunkCount); download.AppendLog(Environment.NewLine + "Maximum connection count: " + maxConnectionCount); List <string> webChunkFilenames = new List <string>(); List <WebChunk> downloadQueue = new List <WebChunk>(); int counter = 0; download.AppendLog(Environment.NewLine + Environment.NewLine + "Initializing video chunk download queue..."); foreach (string webChunk in webChunkList) { string filename = Path.Combine(outputDir, counter.ToString("D8") + ".ts"); webChunkFilenames.Add(filename); downloadQueue.Add(new WebChunk(filename, webChunkUrlPrefix + webChunk)); counter++; cancellationToken.ThrowIfCancellationRequested(); } download.AppendLog(" done!"); download.AppendLog(Environment.NewLine + "Starting parallel video chunk download..."); download.Status = "Downloading"; download.AppendLog(Environment.NewLine + Environment.NewLine + "Parallel video chunk download is running..."); object percentageLock = new object(); Parallel.ForEach(downloadQueue, new ParallelOptions() { MaxDegreeOfParallelism = maxConnectionCount - 1 }, (webChunk, loopState) => { using (WebClient downloadClient = new WebClient()) { byte[] bytes = downloadClient.DownloadData(webChunk.Url); Interlocked.Increment(ref completedChunkDownloads); FileSystem.DeleteFile(webChunk.Filename); File.WriteAllBytes(webChunk.Filename, bytes); long completed = Interlocked.Read(ref completedChunkDownloads); lock (percentageLock) { download.Progress = (int)(completedChunkDownloads * 100 / webChunkCount); } } if (cancellationToken.IsCancellationRequested) { loopState.Stop(); } }); download.Progress = 100; cancellationToken.ThrowIfCancellationRequested(); download.AppendLog(" done!"); download.AppendLog(Environment.NewLine + Environment.NewLine + "Download of all video chunks complete!"); download.AppendLog(Environment.NewLine + Environment.NewLine + "Creating local m3u8 playlist for FFMPEG"); int chunkIndex = 0; for (int i = 0; i < playlistLines.Count; i++) { if (!playlistLines[i].StartsWith("#")) { playlistLines[i] = webChunkFilenames[chunkIndex]; chunkIndex++; } } string newPlaylistStr = string.Join("\n", playlistLines); FileSystem.DeleteFile(playlistFile); download.AppendLog(Environment.NewLine + "Writing playlist to '" + playlistFile + "'"); File.WriteAllText(playlistFile, newPlaylistStr); download.Status = "Encoding"; download.Progress = 0; download.AppendLog(Environment.NewLine + Environment.NewLine + "Executing '" + ffmpegFile + "' on local playlist..."); cancellationToken.ThrowIfCancellationRequested(); ProcessStartInfo psi = new ProcessStartInfo(ffmpegFile); psi.Arguments = "-y -i \"" + playlistFile + "\" -c:v copy -c:a copy -bsf:a aac_adtstoasc \"" + outputFile + "\""; psi.RedirectStandardError = true; psi.RedirectStandardOutput = true; psi.StandardErrorEncoding = Encoding.UTF8; psi.StandardOutputEncoding = Encoding.UTF8; psi.UseShellExecute = false; psi.CreateNoWindow = true; download.AppendLog(Environment.NewLine + "Command line arguments: " + psi.Arguments + Environment.NewLine); using (Process p = new Process()) { TimeSpan duration = new TimeSpan(); DataReceivedEventHandler outputDataReceived = new DataReceivedEventHandler((s, e) => { if (!string.IsNullOrWhiteSpace(e.Data)) { string dataTrimmed = e.Data.Trim(); if (dataTrimmed.StartsWith("Duration")) { string durationStr = dataTrimmed.Substring(dataTrimmed.IndexOf(":") + 1).Trim(); durationStr = durationStr.Substring(0, durationStr.IndexOf(",")).Trim(); duration = TimeSpan.Parse(durationStr); } if (dataTrimmed.StartsWith("frame")) { string timeStr = dataTrimmed.Substring(dataTrimmed.IndexOf("time") + 4).Trim(); timeStr = timeStr.Substring(timeStr.IndexOf("=") + 1).Trim(); timeStr = timeStr.Substring(0, timeStr.IndexOf(" ")).Trim(); TimeSpan current = TimeSpan.Parse(timeStr); lock (percentageLock) { download.Progress = (int)(current.TotalMilliseconds * 100 / duration.TotalMilliseconds); } } download.AppendLog(Environment.NewLine + e.Data); } }); p.OutputDataReceived += outputDataReceived; p.ErrorDataReceived += outputDataReceived; p.StartInfo = psi; p.Start(); p.BeginErrorReadLine(); p.BeginOutputReadLine(); p.WaitForExit(); } download.AppendLog(Environment.NewLine + Environment.NewLine + "Encoding complete!"); } }, cancellationTokenSource.Token); Task continueTask = downloadVideoTask.ContinueWith(task => { download.AppendLog(Environment.NewLine + Environment.NewLine + "Starting temporary download folder cleanup!"); this.CleanUp(outputDir, download); download.Progress = 100; if (task.IsFaulted) { download.DownloadStatus = DownloadStatus.Error; download.AppendLog(Environment.NewLine + Environment.NewLine + "Download task ended with an error!"); if (task.Exception != null) { download.AppendLog(Environment.NewLine + Environment.NewLine + task.Exception.ToString()); } } else if (task.IsCanceled) { download.DownloadStatus = DownloadStatus.Canceled; download.AppendLog(Environment.NewLine + Environment.NewLine + "Download task was canceled!"); } else { download.DownloadStatus = DownloadStatus.Finished; download.AppendLog(Environment.NewLine + Environment.NewLine + "Download task ended successfully!"); } DownloadTask downloadTask; if (!this.downloadTasks.TryRemove(video.Id, out downloadTask)) { throw new ApplicationException("Could not remove download task with ID '" + video.Id + "' from download task collection!"); } }); if (this.downloadTasks.TryAdd(video.Id, new DownloadTask(downloadVideoTask, continueTask, cancellationTokenSource))) { downloadVideoTask.Start(); download.DownloadStatus = DownloadStatus.Active; } } } } finally { Monitor.Exit(this.changeDownloadLockObject); } } }
public static System.Diagnostics.Process SpawnProcess(string exe, string args, string workingDir, KeyValuePair <string, string>[] env, DataReceivedEventHandler outputHandler, DataReceivedEventHandler errorHandler) { try { System.Diagnostics.Process proc = new System.Diagnostics.Process(); proc.StartInfo.UseShellExecute = false; if (workingDir != null) { proc.StartInfo.WorkingDirectory = workingDir; } proc.StartInfo.RedirectStandardError = true; proc.StartInfo.RedirectStandardOutput = true; proc.StartInfo.FileName = exe; proc.StartInfo.Arguments = args; if (env != null) { foreach (KeyValuePair <string, string> kv in env) { if (kv.Key.ToLower() == "path") { try { string path = proc.StartInfo.EnvironmentVariables["Path"]; if (path != null) { path += string.Format(";{0}", kv.Value); } else { path = kv.Value; } proc.StartInfo.EnvironmentVariables["Path"] = path; } catch (Exception e) { EucaLogger.Exception(EucaLogger.LOG_WARNING, "couldn't set path variable", e); } } else { proc.StartInfo.EnvironmentVariables.Add(kv.Key, kv.Value); } } } if (outputHandler != null) { proc.OutputDataReceived += outputHandler; } if (errorHandler != null) { proc.ErrorDataReceived += errorHandler; } proc.Start(); return(proc); } catch (Exception e) { throw new EucaException("Execution failed: " + e.Message, e); } }
public static void RebuildCache(string sourcePath, DataReceivedEventHandler stdoutDataReveiver = null, bool backgroundThread = false) { lock (_rebuildingInProgress) { if ((bool)_rebuildingInProgress) { throw new InvalidOperationException(Language.Message("WaitUntilTheEarlierDoxygenRebuild")); } } var sourceDir = new DirectoryInfo(sourcePath); var outputDir = new DirectoryInfo(DoxygenXmlPath); DirectoryInfo randomTmpDir = null; if (outputDir.Parent == null) { throw new ArgumentException(Language.Message("DoxygenOutputDirShouldHaveAParentDir")); } while (randomTmpDir == null || randomTmpDir.Exists) { randomTmpDir = new DirectoryInfo(outputDir.Parent.FullName + Guid.NewGuid()); } if (!sourceDir.Exists) { throw new ArgumentException(Language.Message("BadParameters")); } var foldersToParse = new string[] { "Runtime", "Developer", "Editor" }; if (DoxygenExec == null || !DoxygenExec.Exists) { throw new DoxygenExecMissing(); } Action runDoxygen = () => { lock (_rebuildingInProgress) { _rebuildingInProgress = true; } RunDoxygen( foldersToParse.Select(folder => Path.Combine(sourceDir.FullName, folder)), randomTmpDir.FullName, stdoutDataReveiver); // Try 5 times with 0.5 second sleep to let the os refresh after deletion. if (outputDir.Exists) { try { RetryIfException( () => outputDir.Delete(true), e => e is IOException || e is UnauthorizedAccessException || e is SecurityException); } catch (DirectoryNotFoundException) { // This shouldn't happen (because I'm checking if the dir exists). // Nevertheless it happened during debugging session, so to be safe, // we just assume that dir is deleted then and ignore the exception. } } RetryIfException(() => randomTmpDir.MoveTo(outputDir.FullName), e => e is IOException); lock (_rebuildingInProgress) { _rebuildCacheThread = null; _rebuildingInProgress = false; } if (DoxygenRebuildingFinished != null) { DoxygenRebuildingFinished(); } }; if (backgroundThread) { _rebuildCacheThread = new Thread(new ThreadStart(runDoxygen)); _rebuildCacheThread.Start(); } else { runDoxygen(); } }
private void GetBlenderPlugin() { string blender = BlenderPath.Text; Task.Run(async() => { DataReceivedEventHandler action = (object s, DataReceivedEventArgs e) => SafePushError(e.Data, Brushes.Gray); //download plugin string path = Path.Combine(Environment.CurrentDirectory, "plugin.zip"); if (!File.Exists(path)) { using (var client = new WebClient()) { //progress changed client.DownloadProgressChanged += async(object sender, DownloadProgressChangedEventArgs e) => { var args = new InstallationCompletionInfo() { StepName = "3D Model Creation", CurrentTask = $"Downloading ({e.BytesReceived / e.TotalBytesToReceive} bytes)", PercentComplete = e.ProgressPercentage / 100.0 }; InstallationInformationChanged(args); }; await client.DownloadFileTaskAsync( new Uri("https://github.com/joric/io_scene_b3d/releases/download/1.0/io_scene_b3d.zip"), "plugin.zip"); } } string pluginPath = Path.Combine(Environment.CurrentDirectory, "InstallPlugin.py"); PythonParameterEditor.ReplaceParameter(pluginPath, "filepath=", 0, path.Replace('\\', '/')); ProcessStartInfo startInfo = new ProcessStartInfo(blender, $"-b -P {pluginPath}") { CreateNoWindow = true, UseShellExecute = false, RedirectStandardOutput = true }; var info = Process.Start(startInfo); try { info.BeginOutputReadLine(); info.OutputDataReceived += action; } catch (Exception e) { SafePushError(e.Message); } Dispatcher.Invoke(delegate { InstallationInformationChanged(new InstallationCompletionInfo() { StepName = "3D Model Creation", CurrentTask = $"Installing Blender Addon...", PercentComplete = 0.0 }); WaitForUserCompletion(); MsgOKButton.IsEnabled = false; MsgOKButton.Content = "Blender is open"; }); info.WaitForExit(); try { info.CancelOutputRead(); info.OutputDataReceived -= action; } catch (Exception e) { PushError(e.Message); } Dispatcher.Invoke(delegate { InstallationInformationChanged(new InstallationCompletionInfo() { StepName = "3D Model Creation", CurrentTask = $"Installing Blender Addon...", PercentComplete = 1.0 }); if (info.ExitCode == 0) { MsgTitle.Text = "Good to Go!"; MsgOKButton.IsEnabled = true; MsgOKButton.Content = "All set"; } else { MsgTitle.Text = "Blender had an error"; MsgOKButton.IsEnabled = false; MsgOKButton.Content = "Try again later"; } }); }).ContinueWith((Task task) => { if (task.IsFaulted) { SafePushError(task.Exception.Flatten().InnerException.Message); Installation?.TogglePause(); } }); }
public Task <string> ArduinoToHexAsync(string filepath, bool baseDirectory, DataReceivedEventHandler listener) { return(Task.Run(() => ArduinoToHex(filepath, baseDirectory, listener))); }
private Process StartProcessAsync(string arguments, DataReceivedEventHandler outputDataReceived = null, DataReceivedEventHandler errorDataReceived = null) { var proc = new Process { StartInfo = { FileName = "Resources//youtube-dl.exe", Arguments = arguments, UseShellExecute = false, CreateNoWindow = true, RedirectStandardOutput = true } }; proc.OutputDataReceived += outputDataReceived ?? OutputDataReceived; proc.ErrorDataReceived += errorDataReceived ?? ErrorDataReceived; proc.Start(); proc.BeginOutputReadLine(); return(proc); }
public static Process StartProcess( string fileName, IEnumerable <string> arguments, string workingDirectory, DataReceivedEventHandler standardOutputHandler, DataReceivedEventHandler standardErrorHandler) { var redirectOutput = standardOutputHandler != null; var redirectError = standardErrorHandler != null; var process = new Process(); process.StartInfo.FileName = fileName; process.StartInfo.CreateNoWindow = true; if (!string.IsNullOrEmpty(workingDirectory)) { process.StartInfo.WorkingDirectory = workingDirectory; } if (redirectOutput) { process.StartInfo.RedirectStandardOutput = true; process.OutputDataReceived += standardOutputHandler; } if (redirectError) { process.StartInfo.RedirectStandardError = true; process.ErrorDataReceived += standardErrorHandler; } if (arguments != null) { foreach (var argument in arguments) { process.StartInfo.ArgumentList.Add(argument); } } var hasStarted = process.Start(); if (!hasStarted) { throw new InvalidOperationException( "Process failed to start. The command used to run the process was:" + Environment.NewLine + $"{fileName} {string.Join(" ", arguments)}"); } if (redirectOutput) { process.BeginOutputReadLine(); } if (redirectError) { process.BeginErrorReadLine(); } return(process); }
public static void RunDoxygen(IEnumerable <string> inputs, string outputDir, DataReceivedEventHandler stdoutDataReveiver = null) { var outputDirInfo = new DirectoryInfo(outputDir); if (!outputDirInfo.Exists) { outputDirInfo.Create(); } var configPath = Path.Combine(outputDir, "doxygen.config"); var template = new DoxygenConfig( string.Join(" \\" + Environment.NewLine, inputs.Select(input => "\"" + input + "\"")), "\"" + outputDir + "\""); File.WriteAllText(configPath, template.TransformText()); var doxygenProcess = new Process { StartInfo = { UseShellExecute = false, RedirectStandardOutput = true, FileName = DoxygenExec.FullName, Arguments = configPath, CreateNoWindow = true }, EnableRaisingEvents = true }; // The progress estimation is not accurate. It divides the process into 3 equal // parts: first parsing input files, second building group list and third finished. // Each of these parts may last variable amount of time. It can be improved, but // it will require some research and implementation. The += 0.0000333 on every // stdout newline gives the impression of progress. If it is not enough, please // TTP it. double lastProgress = 0.0; doxygenProcess.OutputDataReceived += (sender, args) => { if (args.Data == null) { ProgressChanged(1.0); return; } switch (args.Data) { case "Building group list...": lastProgress = 1.0 / 3.0; break; case "Generating XML output...": lastProgress = 2.0 / 3.0; break; case "finished...": // when it's finished then return ProgressChanged(1.0); return; default: lastProgress += 0.0000333; break; } if (lastProgress > 0.0 && lastProgress < 1.0) { ProgressChanged(lastProgress); } if (lastProgress >= 1.0) { // almost finished ProgressChanged(0.9999999); } }; if (stdoutDataReveiver != null) { doxygenProcess.OutputDataReceived += stdoutDataReveiver; } if (doxygenProcess.Start()) { doxygenProcess.BeginOutputReadLine(); doxygenProcess.WaitForExit(); } }
public void TimeDeploy() { if (adbTool != null) { TransferStarted = false; DataReceivedEventHandler outputRecieved = new DataReceivedEventHandler( (s, e) => { if (e.Data != null && e.Data.Length != 0 && !e.Data.Contains("\u001b")) { if (e.Data.Contains("free_cache")) { // Device recieved install command and is starting upload UploadStart = System.DateTime.Now; TransferStarted = true; } else if (e.Data.Contains("Running dexopt")) { // Upload has finished and Package Manager is starting install UploadEnd = System.DateTime.Now; } else if (e.Data.Contains("dex2oat took")) { // Package Manager finished install InstallEnd = System.DateTime.Now; WaitForProcess = false; } else if (e.Data.Contains("W PackageManager")) { // Warning from Package Manager is a failure in the install process WaitForProcess = false; } } } ); WaitForProcess = true; adbProcess = adbTool.RunCommandAsync(new string[] { "logcat" }, outputRecieved); Stopwatch transferTimeout = new Stopwatch(); transferTimeout.Start(); while (adbProcess != null && !adbProcess.WaitForExit(100)) { if (!WaitForProcess) { adbProcess.Kill(); float UploadTime = (float)(UploadEnd - UploadStart).TotalMilliseconds / 1000f; float InstallTime = (float)(InstallEnd - UploadEnd).TotalMilliseconds / 1000f; if (UploadTime > 0f) { OVRPlugin.SendEvent("deploy_task", UploadTime.ToString(), "ovrbuild"); } if (InstallTime > 0f) { OVRPlugin.SendEvent("install_task", InstallTime.ToString(), "ovrbuild"); } } if (!TransferStarted && transferTimeout.ElapsedMilliseconds > 5000) { adbProcess.Kill(); } } } }
public static int RunProcess(string name, string args, DataReceivedEventHandler onOutput, DataReceivedEventHandler onError) { var psi = new ProcessStartInfo(name, args) { UseShellExecute = false, RedirectStandardOutput = true, RedirectStandardError = true, CreateNoWindow = true, WindowStyle = ProcessWindowStyle.Hidden, }; Process p = new Process(); p.StartInfo = psi; p.OutputDataReceived += onOutput; p.ErrorDataReceived += onError; p.Start(); p.BeginErrorReadLine(); p.BeginOutputReadLine(); p.WaitForExit(); try { return(p.ExitCode); } finally { p.Close(); } }
private AzAccessToken[] GetAzLoginTokens() { var azCmd = Environment.ExpandEnvironmentVariables(@"%ProgramFiles(x86)%\Microsoft SDKs\Azure\CLI2\wbin\az.cmd"); if (!File.Exists(azCmd)) { throw new InvalidOperationException("Azure cli is required. Please download and install from https://aka.ms/InstallAzureCliWindows"); } var accessTokensFile = Environment.ExpandEnvironmentVariables(@"%USERPROFILE%\.azure\accessTokens.json"); var backupContent = File.Exists(accessTokensFile) ? File.ReadAllText(accessTokensFile) : null; try { if (File.Exists(accessTokensFile)) { File.Delete(accessTokensFile); } var processInfo = new ProcessStartInfo(azCmd, "login"); processInfo.CreateNoWindow = true; processInfo.UseShellExecute = false; processInfo.RedirectStandardError = true; processInfo.RedirectStandardOutput = true; // start var process = Process.Start(processInfo); var processName = process.ProcessName; var processId = process.Id; // hook process event var processEvent = new ManualResetEvent(true); processEvent.SafeWaitHandle = new SafeWaitHandle(process.Handle, false); var hasOutput = false; var stdOutput = new StringBuilder(); DataReceivedEventHandler stdHandler = (object sender, DataReceivedEventArgs e) => { if (e.Data != null) { if (!hasOutput) { Console.WriteLine(); hasOutput = true; } if (e.Data.IndexOf("[") >= 0 || stdOutput.Length > 0) { stdOutput.Append(e.Data); } else { Console.Write(e.Data); } } }; // hoook stdout and stderr process.OutputDataReceived += stdHandler; process.BeginOutputReadLine(); process.ErrorDataReceived += stdHandler; process.BeginErrorReadLine(); // wait for ready Console.Write("Executing az login."); while (!processEvent.WaitOne(2000) && !hasOutput) { Console.Write("."); } processEvent.WaitOne(); if (process.ExitCode != 0) { // if success, it contains the list of subscriptions Console.WriteLine(stdOutput); throw new InvalidOperationException("Process exit with " + process.ExitCode); } return(JsonConvert.DeserializeObject <AzAccessToken[]>(File.ReadAllText(accessTokensFile))); } finally { if (backupContent != null) { File.WriteAllText(accessTokensFile, backupContent); } else { File.Delete(accessTokensFile); } } }
bool TryCompileSingleFile() { DTE DTE = UnrealVSPackage.Instance.DTE; // Activate the output window Window Window = DTE.Windows.Item(EnvDTE.Constants.vsWindowKindOutput); Window.Activate(); OutputWindow OutputWindow = Window.Object as OutputWindow; // Try to find the 'Build' window OutputWindowPane BuildOutputPane = null; foreach (OutputWindowPane Pane in OutputWindow.OutputWindowPanes) { if (Pane.Guid.ToUpperInvariant() == "{1BD8A850-02D1-11D1-BEE7-00A0C913D1F8}") { BuildOutputPane = Pane; break; } } if (BuildOutputPane == null) { return(false); } // If there's already a build in progress, offer to cancel it if (ChildProcess != null && !ChildProcess.HasExited) { if (MessageBox.Show("Cancel current compile?", "Compile in progress", MessageBoxButtons.YesNo) == DialogResult.Yes) { KillChildProcess(); BuildOutputPane.OutputString("1> Build cancelled.\r\n"); } return(true); } // Check we've got a file open if (DTE.ActiveDocument == null) { return(false); } // Grab the current startup project IVsHierarchy ProjectHierarchy; UnrealVSPackage.Instance.SolutionBuildManager.get_StartupProject(out ProjectHierarchy); if (ProjectHierarchy == null) { return(false); } Project StartupProject = Utils.HierarchyObjectToProject(ProjectHierarchy); if (StartupProject == null) { return(false); } Microsoft.VisualStudio.VCProjectEngine.VCProject VCStartupProject = StartupProject.Object as Microsoft.VisualStudio.VCProjectEngine.VCProject; if (VCStartupProject == null) { return(false); } // Get the active configuration for the startup project Configuration ActiveConfiguration = StartupProject.ConfigurationManager.ActiveConfiguration; string ActiveConfigurationName = String.Format("{0}|{1}", ActiveConfiguration.ConfigurationName, ActiveConfiguration.PlatformName); Microsoft.VisualStudio.VCProjectEngine.VCConfiguration ActiveVCConfiguration = VCStartupProject.Configurations.Item(ActiveConfigurationName); if (ActiveVCConfiguration == null) { return(false); } // Get the NMake settings for this configuration Microsoft.VisualStudio.VCProjectEngine.VCNMakeTool ActiveNMakeTool = ActiveVCConfiguration.Tools.Item("VCNMakeTool"); if (ActiveNMakeTool == null) { return(false); } // Save all the open documents DTE.ExecuteCommand("File.SaveAll"); // Check it's a cpp file string FileToCompile = DTE.ActiveDocument.FullName; if (!FileToCompile.EndsWith(".c", StringComparison.InvariantCultureIgnoreCase) && !FileToCompile.EndsWith(".cpp", StringComparison.InvariantCultureIgnoreCase)) { MessageBox.Show("Invalid file extension for single-file compile.", "Invalid Extension", MessageBoxButtons.OK); return(true); } // If there's already a build in progress, don't let another one start if (DTE.Solution.SolutionBuild.BuildState == vsBuildState.vsBuildStateInProgress) { if (MessageBox.Show("Cancel current compile?", "Compile in progress", MessageBoxButtons.YesNo) == DialogResult.Yes) { DTE.ExecuteCommand("Build.Cancel"); } return(true); } // Make sure any existing build is stopped KillChildProcess(); // Set up the output pane BuildOutputPane.Activate(); BuildOutputPane.Clear(); BuildOutputPane.OutputString(String.Format("1>------ Build started: Project: {0}, Configuration: {1} {2} ------\r\n", StartupProject.Name, ActiveConfiguration.ConfigurationName, ActiveConfiguration.PlatformName)); BuildOutputPane.OutputString(String.Format("1> Compiling {0}\r\n", FileToCompile)); // Set up event handlers DTE.Events.BuildEvents.OnBuildBegin += BuildEvents_OnBuildBegin; // Create a delegate for handling output messages DataReceivedEventHandler OutputHandler = (Sender, Args) => { if (Args.Data != null) { BuildOutputPane.OutputString("1> " + Args.Data + "\r\n"); } }; // Get the build command line and escape any environment variables that we use string BuildCommandLine = ActiveNMakeTool.BuildCommandLine; BuildCommandLine = BuildCommandLine.Replace("$(SolutionDir)", Path.GetDirectoryName(UnrealVSPackage.Instance.SolutionFilepath).TrimEnd(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar); BuildCommandLine = BuildCommandLine.Replace("$(ProjectName)", VCStartupProject.Name); // Spawn the new process ChildProcess = new System.Diagnostics.Process(); ChildProcess.StartInfo.FileName = Path.Combine(Environment.SystemDirectory, "cmd.exe"); ChildProcess.StartInfo.Arguments = String.Format("/C {0} -singlefile=\"{1}\"", BuildCommandLine, FileToCompile); ChildProcess.StartInfo.WorkingDirectory = Path.GetDirectoryName(StartupProject.FullName); ChildProcess.StartInfo.UseShellExecute = false; ChildProcess.StartInfo.RedirectStandardOutput = true; ChildProcess.StartInfo.RedirectStandardError = true; ChildProcess.StartInfo.CreateNoWindow = true; ChildProcess.OutputDataReceived += OutputHandler; ChildProcess.ErrorDataReceived += OutputHandler; ChildProcess.Start(); ChildProcess.BeginOutputReadLine(); ChildProcess.BeginErrorReadLine(); return(true); }
public bool startJavaShell(DataReceivedEventHandler dataReceivedCallBack, string _classPath, string _classToExecute, string extraExecutionArguments) { return(startJavaShell(dataReceivedCallBack, "")); }
// To enable unit testing internal int Execute( IServiceProvider serviceProvider, IConsole console, DataReceivedEventHandler stdOutHandler, DataReceivedEventHandler stdErrHandler) { var logger = serviceProvider.GetRequiredService <ILogger <BuildCommand> >(); // This will be an App Service app name if Oryx was invoked by Kudu var appName = Environment.GetEnvironmentVariable(LoggingConstants.AppServiceAppNameEnvironmentVariableName) ?? ".oryx"; var buildOpId = logger.StartOperation(appName); var buildInfo = new DefinitionListFormatter(); buildInfo.AddDefinition("Build Operation ID", buildOpId); buildInfo.AddDefinition("Oryx Version", $"{Program.GetVersion()}, Commit: {Program.GetCommit()}"); var sourceRepo = serviceProvider.GetRequiredService <ISourceRepoProvider>().GetSourceRepo(); var commitId = GetSourceRepoCommitId(serviceProvider.GetRequiredService <IEnvironment>(), sourceRepo, logger); if (!string.IsNullOrWhiteSpace(commitId)) { buildInfo.AddDefinition("Repository Commit", commitId); } console.WriteLine(buildInfo.ToString()); // Try writing the ID to a file in the source directory try { using (logger.LogTimedEvent("WriteBuildIdFile")) using (var idFileWriter = new StreamWriter(Path.Combine(sourceRepo.RootPath, Common.FilePaths.BuildIdFileName))) { idFileWriter.Write(buildOpId); } } catch (Exception exc) { logger.LogError(exc, "Exception caught while trying to write build ID file"); } var environmentSettingsProvider = serviceProvider.GetRequiredService <IEnvironmentSettingsProvider>(); if (!environmentSettingsProvider.TryGetAndLoadSettings(out var environmentSettings)) { return(ProcessConstants.ExitFailure); } // Generate build script string scriptContent; using (var stopwatch = logger.LogTimedEvent("GenerateBuildScript")) { var scriptGenerator = new BuildScriptGenerator(console, serviceProvider); if (!scriptGenerator.TryGenerateScript(out scriptContent)) { stopwatch.AddProperty("failed", "true"); return(ProcessConstants.ExitFailure); } } // Get the path where the generated script should be written into. var tempDirectoryProvider = serviceProvider.GetRequiredService <ITempDirectoryProvider>(); var buildScriptPath = Path.Combine(tempDirectoryProvider.GetTempDirectory(), "build.sh"); // Write build script to selected path File.WriteAllText(buildScriptPath, scriptContent); logger.LogTrace("Build script written to file"); var buildEventProps = new Dictionary <string, string>() { { "oryxVersion", Program.GetVersion() }, { "oryxCommitId", Program.GetCommit() }, { "oryxCommandLine", string.Join(' ', serviceProvider.GetRequiredService <IEnvironment>().GetCommandLineArgs()) }, { nameof(commitId), commitId }, { "scriptPath", buildScriptPath }, { "envVars", string.Join(",", GetEnvVarNames(serviceProvider.GetRequiredService <IEnvironment>())) }, }; var buildScriptOutput = new StringBuilder(); DataReceivedEventHandler stdOutBaseHandler = (sender, args) => { console.WriteLine(args.Data); buildScriptOutput.AppendLine(args.Data); }; DataReceivedEventHandler stdErrBaseHandler = (sender, args) => { console.Error.WriteLine(args.Data); buildScriptOutput.AppendLine(args.Data); }; // Try make the pre-build & post-build scripts executable ProcessHelper.TrySetExecutableMode(environmentSettings.PreBuildScriptPath); ProcessHelper.TrySetExecutableMode(environmentSettings.PostBuildScriptPath); // Run the generated script var options = serviceProvider.GetRequiredService <IOptions <BuildScriptGeneratorOptions> >().Value; int exitCode; using (var timedEvent = logger.LogTimedEvent("RunBuildScript", buildEventProps)) { exitCode = serviceProvider.GetRequiredService <IScriptExecutor>().ExecuteScript( buildScriptPath, new[] { sourceRepo.RootPath, options.DestinationDir ?? string.Empty }, workingDirectory: sourceRepo.RootPath, stdOutHandler == null ? stdOutBaseHandler : stdOutBaseHandler + stdOutHandler, stdErrHandler == null ? stdErrBaseHandler : stdErrBaseHandler + stdErrHandler); } logger.LogDebug("Build script content:\n" + scriptContent); logger.LogDebug("Build script output:\n" + buildScriptOutput.ToString()); if (exitCode != ProcessConstants.ExitSuccess) { logger.LogError("Build script exited with {exitCode}", exitCode); return(exitCode); } return(ProcessConstants.ExitSuccess); }
static int Main(string [] args) { int rv = 0; if (args.Length < 1) { Console.WriteLine("A command to execute must be specified"); return(1); } // For now we only look in the current directory for libLeakCheckAtExit.dylib. // We might have to improve that if this tool grows. var libLeakCheckAtExit = Path.GetFullPath("libLeakCheckAtExit.dylib"); if (!File.Exists(libLeakCheckAtExit)) { Console.WriteLine("Could not find libLeakCheckAtExit.dylib"); return(1); } var pid = Process.GetCurrentProcess().Id; var ready_file = Path.GetFullPath($".stamp-ready-{pid}"); // this file is removed when the test app is ready for leak check var done_file = Path.GetFullPath($".stamp-done-{pid}"); // this file is removed when the leak check is complete, this means the test app can exit File.WriteAllText(ready_file, string.Empty); File.WriteAllText(done_file, string.Empty); Environment.SetEnvironmentVariable("LEAK_READY_FILE", ready_file); Environment.SetEnvironmentVariable("LEAK_DONE_FILE", done_file); using (var p = new Process()) { p.StartInfo.FileName = args [0]; var sb = new StringBuilder(); for (int i = 1; i < args.Length; i++) { sb.Append(" \"").Append(args [i]).Append("\""); } p.StartInfo.Arguments = sb.ToString(); p.StartInfo.EnvironmentVariables.Add("MallocStackLogging", "1"); p.StartInfo.EnvironmentVariables.Add("MallocScribble", "1"); p.StartInfo.EnvironmentVariables.Add("DYLD_INSERT_LIBRARIES", libLeakCheckAtExit); p.StartInfo.UseShellExecute = false; Console.WriteLine("Executing: {0} {1}", p.StartInfo.FileName, p.StartInfo.Arguments); p.Start(); while (File.Exists(ready_file)) { Thread.Sleep(100); if (p.HasExited) { Console.WriteLine("App crashed/exited, no leak check can be performed."); return(1); } } Console.WriteLine("Performing leak test..."); using (var leaks = new Process()) { var sudo = !HasControllingTerminal(); leaks.StartInfo.FileName = sudo ? "sudo" : "xcrun"; sb.Clear(); if (sudo) { sb.Append("--non-interactive xcrun "); } sb.Append($"leaks {p.Id}"); sb.Append(" -exclude mono_save_seq_point_info"); // I haven't investigated this sb.Append(" -exclude create_internal_thread_object"); // I haven't investigated this sb.Append(" -exclude mono_thread_attach_internal"); // I haven't investigated this (and it seems random) sb.Append(" -exclude mono_thread_set_name_internal"); // I haven't investigated this (and it seems random) sb.Append(" -exclude mono_assembly_load_from_full"); // there's a leak in aot-runtime.c:check_usable if multiple error conditions sb.Append(" -exclude load_aot_module"); // This happens with Mono 5.2.0.7 (master/bb9c915) - but not Mono 5.0.0.18 (2017-02/9ed0907). Fix suggested: https://github.com/mono/mono/pull/4643 sb.Append(" -exclude setup_jit_tls_data"); // https://bugzilla.xamarin.com/show_bug.cgi?id=56722 leaks.StartInfo.Arguments = sb.ToString(); leaks.StartInfo.UseShellExecute = false; leaks.StartInfo.RedirectStandardOutput = true; leaks.StartInfo.RedirectStandardError = true; DataReceivedEventHandler process_output = (object sender, DataReceivedEventArgs ea) => { var line = ea.Data; if (line == null) { return; } if (!line.StartsWith("\tCall stack: ", StringComparison.Ordinal)) { Console.WriteLine(line); return; } line = line.Substring("\tCall stack: ".Length); var frames = new List <string> (line.Split(new string [] { " | " }, StringSplitOptions.None)); if (frames.Count > 1 && frames [1] == "0x1") { frames.RemoveAt(1); } frames.Reverse(); Console.WriteLine("\tCall stack: "); foreach (var frame in frames) { Console.WriteLine($"\t\t{frame}"); } }; leaks.ErrorDataReceived += process_output; leaks.OutputDataReceived += process_output; Console.WriteLine("{0} {1}", leaks.StartInfo.FileName, leaks.StartInfo.Arguments); leaks.Start(); leaks.BeginErrorReadLine(); leaks.BeginOutputReadLine(); leaks.WaitForExit(); Console.WriteLine("Done performing leak test, result: {0}", leaks.ExitCode); rv = leaks.ExitCode; } File.Delete(done_file); Console.WriteLine("Waiting for app to terminate..."); p.WaitForExit(); Console.WriteLine($"Done with exit code {p.ExitCode}"); } return(rv); }
public static int RunProcess(string name, string args, DataReceivedEventHandler onOutput, DataReceivedEventHandler onError, Dictionary <string, string> environmentVariables = null) { var psi = new ProcessStartInfo(name, args) { UseShellExecute = false, RedirectStandardOutput = true, RedirectStandardError = true, CreateNoWindow = true, WindowStyle = ProcessWindowStyle.Hidden, }; if (environmentVariables != null) { foreach (var pair in environmentVariables) { psi.EnvironmentVariables [pair.Key] = pair.Value; } } Process p = new Process(); p.StartInfo = psi; p.OutputDataReceived += onOutput; p.ErrorDataReceived += onError; p.Start(); p.BeginErrorReadLine(); p.BeginOutputReadLine(); p.WaitForExit(); try { return(p.ExitCode); } finally { p.Close(); } }
/// <summary> /// GetVideoInfo /// </summary> /// <param name="videoFilePath">path to the video</param> /// <returns></returns> public AnalyzeResult GetVideoInfo(string videoFilePath) { if (!File.Exists(videoFilePath)) { if (!IsValidURL(videoFilePath)) { return(new AnalyzeResult { Successful = false, ErrorMessage = "File does not exist" }); } } if (!File.Exists(this._ffprobePath)) { return(new AnalyzeResult { Successful = false, ErrorMessage = $"ffprobe could not be found {this._ffprobePath}" }); } var startInfo = new ProcessStartInfo { FileName = this._ffprobePath, Arguments = $"-v quiet -print_format json -show_format -show_streams \"{videoFilePath}\"", UseShellExecute = false, RedirectStandardOutput = true, }; using (var outputWaitHandle = new AutoResetEvent(false)) { var json = new StringBuilder(); var dataReceived = new DataReceivedEventHandler((sender, e) => { if (e.Data == null) { outputWaitHandle.Set(); return; } json.AppendLine(e.Data); }); var process = new Process(); try { process.StartInfo = startInfo; process.OutputDataReceived += dataReceived; process.Start(); process.BeginOutputReadLine(); if (!process.WaitForExit(this._timeout) || !outputWaitHandle.WaitOne(this._timeout)) { return(new AnalyzeResult { ErrorMessage = $"Timeout reached {this._timeout} (ms)" }); } var videoInfo = JsonConvert.DeserializeObject <VideoInfoResult>(json.ToString(), this._jsonSerializerSettings); return(new AnalyzeResult { Successful = true, VideoInfo = videoInfo }); } catch (Exception exception) { return(new AnalyzeResult { Successful = false, ErrorMessage = exception.ToString() }); } finally { process.OutputDataReceived -= dataReceived; process?.Dispose(); } } }
private void EncodeVideo(Action <string> log, Action <string> setStatus, Action <int> setProgress, Action <bool> setIsEncoding, string ffmpegFile, string playlistFile, string outputFile, CropInfo cropInfo) { setStatus("Encoding"); setIsEncoding(true); log(Environment.NewLine + Environment.NewLine + "Executing '" + ffmpegFile + "' on local playlist..."); ProcessStartInfo psi = new ProcessStartInfo(ffmpegFile); psi.Arguments = "-y" + (cropInfo.CropStart ? " -ss " + cropInfo.Start.ToString(CultureInfo.InvariantCulture) : null) + " -i \"" + playlistFile + "\" -c:v copy -c:a copy -bsf:a aac_adtstoasc" + (cropInfo.CropEnd ? " -t " + cropInfo.Length.ToString(CultureInfo.InvariantCulture) : null) + " \"" + outputFile + "\""; psi.RedirectStandardError = true; psi.RedirectStandardOutput = true; psi.StandardErrorEncoding = Encoding.UTF8; psi.StandardOutputEncoding = Encoding.UTF8; psi.UseShellExecute = false; psi.CreateNoWindow = true; log(Environment.NewLine + "Command line arguments: " + psi.Arguments + Environment.NewLine); using (Process p = new Process()) { TimeSpan duration = new TimeSpan(); bool durationReceived = false; DataReceivedEventHandler outputDataReceived = new DataReceivedEventHandler((s, e) => { try { if (!string.IsNullOrWhiteSpace(e.Data)) { string dataTrimmed = e.Data.Trim(); if (dataTrimmed.StartsWith("Duration") && !durationReceived) { string durationStr = dataTrimmed.Substring(dataTrimmed.IndexOf(":") + 1).Trim(); durationStr = durationStr.Substring(0, durationStr.IndexOf(",")).Trim(); if (TimeSpan.TryParse(durationStr, out duration)) { duration = TimeSpan.Parse(durationStr); durationReceived = true; setProgress(0); } } if (dataTrimmed.StartsWith("frame") && durationReceived && duration != TimeSpan.Zero) { string timeStr = dataTrimmed.Substring(dataTrimmed.IndexOf("time") + 4).Trim(); timeStr = timeStr.Substring(timeStr.IndexOf("=") + 1).Trim(); timeStr = timeStr.Substring(0, timeStr.IndexOf(" ")).Trim(); TimeSpan current; if (TimeSpan.TryParse(timeStr, out current)) { setIsEncoding(false); setProgress((int)(current.TotalMilliseconds * 100 / duration.TotalMilliseconds)); } else { setIsEncoding(true); } } } } catch (Exception ex) { log(Environment.NewLine + "An error occured while reading '" + ffmpegFile + "' output stream!" + Environment.NewLine + Environment.NewLine + ex.ToString()); } }); p.OutputDataReceived += outputDataReceived; p.ErrorDataReceived += outputDataReceived; p.StartInfo = psi; p.Start(); p.BeginErrorReadLine(); p.BeginOutputReadLine(); p.WaitForExit(); if (p.ExitCode == 0) { log(Environment.NewLine + "Encoding complete!"); } else { throw new ApplicationException("An error occured while encoding the video!"); } } }
public ProcessHelper(DataReceivedEventHandler outputDataReceived, DataReceivedEventHandler errorDataReceived) { this.OutputDataReceived = outputDataReceived; this.ErrorDataReceived = errorDataReceived; }
// ReSharper disable once UnusedMember.Local private static void Generate() { var fileName = "premake5"; if (UnityEngine.Application.platform == RuntimePlatform.WindowsEditor) { fileName = Path.Combine(RootPath, fileName + ".exe"); } using (var process = new Process { StartInfo = new ProcessStartInfo { FileName = fileName, WorkingDirectory = RootPath, Arguments = "--protogen", UseShellExecute = false, RedirectStandardOutput = true, RedirectStandardError = true, CreateNoWindow = true } }) { var timer = new Stopwatch(); DataReceivedEventHandler hander = (sender, e) => { timer.Reset(); timer.Start(); if (!e.Data.Contains(": error CS001: ")) { return; } UnityEngine.Debug.LogError(e.Data.Substring(AssetsPath.Length + 1)); }; process.OutputDataReceived += hander; process.ErrorDataReceived += hander; timer.Start(); process.Start(); process.BeginOutputReadLine(); process.BeginErrorReadLine(); while (!process.WaitForExit(100)) { if (timer.Elapsed.TotalSeconds > 2.5) { UnityEngine.Debug.LogError("Process timed out while generating ProtoBuf classes"); return; } } if (process.ExitCode == 0) { UnityEngine.Debug.Log("Successfully generated ProtoBuf classes"); } else { UnityEngine.Debug.LogError("An error occurred while generating ProtoBuf classes"); } } }
/// <summary> /// Launches a program /// </summary> /// <param name="ProgramFile">Path to the program to run</param> /// <param name="Arguments">Command-line arguments</param> /// <param name="OnExit">Optional callback whent he program exits</param> /// <param name="OutputHandler">If supplied, std-out and std-error will be redirected to this function and no shell window will be created</param> /// <returns>The newly-created process, or null if it wasn't able to start. Exceptions are swallowed, but a debug output string is emitted on errors</returns> public System.Diagnostics.Process LaunchProgram(string ProgramFile, string Arguments, EventHandler OnExit = null, DataReceivedEventHandler OutputHandler = null, bool bWaitForCompletion = false) { // Create the action's process. ProcessStartInfo ActionStartInfo = new ProcessStartInfo(); ActionStartInfo.FileName = ProgramFile; ActionStartInfo.Arguments = Arguments; if (OutputHandler != null) { ActionStartInfo.RedirectStandardInput = true; ActionStartInfo.RedirectStandardOutput = true; ActionStartInfo.RedirectStandardError = true; // True to use a DOS box to run the program in, otherwise false to run directly. In order to redirect // output, UseShellExecute must be disabled ActionStartInfo.UseShellExecute = false; // Don't show the DOS box, since we're redirecting everything ActionStartInfo.CreateNoWindow = true; } Logging.WriteLine(String.Format("Executing: {0} {1}", ActionStartInfo.FileName, ActionStartInfo.Arguments)); System.Diagnostics.Process ActionProcess; try { ActionProcess = new System.Diagnostics.Process(); ActionProcess.StartInfo = ActionStartInfo; if (OnExit != null) { ActionProcess.EnableRaisingEvents = true; ActionProcess.Exited += OnExit; } if (ActionStartInfo.RedirectStandardOutput) { ActionProcess.EnableRaisingEvents = true; ActionProcess.OutputDataReceived += OutputHandler; ActionProcess.ErrorDataReceived += OutputHandler; } // Launch the program ActionProcess.Start(); if (ActionStartInfo.RedirectStandardOutput) { ActionProcess.BeginOutputReadLine(); ActionProcess.BeginErrorReadLine(); } if (bWaitForCompletion) { while ((ActionProcess != null) && (!ActionProcess.HasExited)) { ActionProcess.WaitForExit(50); } } } catch (Exception Ex) { // Couldn't launch program Logging.WriteLine("Couldn't launch program: " + ActionStartInfo.FileName); Logging.WriteLine("Exception: " + Ex.Message); ActionProcess = null; } return(ActionProcess); }
public virtual void RemoveHandler(DataReceivedEventHandler drx) { OutputDataReceived -= new DataReceivedEventHandler(drx); ErrorDataReceived -= new DataReceivedEventHandler(drx); }
internal void FetchProcessInfo(int id) { cmdInfo = new ProcessCommandInfo(); try { if (id != -2147483648) { var startInfo = new ProcessStartInfo("bash", string.Format("-c \"ps -p {0} -xo command && ps -p {0} -xco command && ps -p {0} -xco args && ps -p {0} -xo ppid && ps -p {0} -xo rss && ps -p {0} -xo minflt && ps -p {0} -xo majflt && ps -p {0} -xo sess && ps -p {0} -xo vsz && ps -p {0} -M | wc -l\"", id)) { UseShellExecute = false, CreateNoWindow = false, RedirectStandardOutput = true, RedirectStandardError = true }; string[] resultLines = new string[19]; int i = 0; Process p = Process.Start(startInfo); DataReceivedEventHandler receiveHandler = (object sender, DataReceivedEventArgs e) => { if (i >= resultLines.Length) { return; } if (!string.IsNullOrEmpty(e.Data)) { resultLines[i] = e.Data; } else { resultLines[i] = ""; } i++; }; DataReceivedEventHandler errorHandler = (object sender, DataReceivedEventArgs e) => { }; p.ErrorDataReceived += errorHandler; p.OutputDataReceived += receiveHandler; p.BeginOutputReadLine(); p.WaitForExit(); p.ErrorDataReceived -= errorHandler; p.OutputDataReceived -= receiveHandler; cmdInfo.CommandLine = resultLines[1]; string fileName = resultLines[3]; string args = resultLines[5]; cmdInfo.ProcessName = fileName; cmdInfo.FileName = cmdInfo.CommandLine.Replace(args, fileName); args = args.Replace(fileName, ""); if (args.StartsWith(" ")) { args = args.Substring(1); } cmdInfo.Arguments = args; int ppid; if (int.TryParse(resultLines[7].Trim(), out ppid)) { cmdInfo.ParentProcessId = ppid; } uint maxWSize; if (uint.TryParse(resultLines[9].Trim(), out maxWSize)) { cmdInfo.MaxWorkingSetSize = maxWSize; } uint minWSize; if (uint.TryParse(resultLines[9].Trim(), out minWSize)) { cmdInfo.MinWorkingSetSize = minWSize; } uint maxPf; if (uint.TryParse(resultLines[11].Trim(), out maxPf)) { cmdInfo.MajorPageFaults = maxPf; } uint minPf; if (uint.TryParse(resultLines[13].Trim(), out minPf)) { cmdInfo.MinorPageFaults = minPf; } uint sess; if (uint.TryParse(resultLines[15].Trim(), out sess)) { cmdInfo.SessionId = sess; } ulong vmem; if (ulong.TryParse(resultLines[17].Trim(), out vmem)) { cmdInfo.VirtualMemorySize = vmem; } uint thcount; if (uint.TryParse(resultLines[18].Trim(), out thcount)) { cmdInfo.ThreadsCount = thcount; } } } catch (Win32Exception) { } catch (InvalidOperationException) { } }
void Run(string emulator) { if (emulator == null) { return; } var port = string.IsNullOrEmpty(Port) ? "" : $" -port {Port}"; var arguments = $"-verbose -avd {ImageName}{port} -cache-size 512"; Log.LogMessage(MessageImportance.Low, $"Tool {emulator} execution started with arguments: {arguments}"); var psi = new ProcessStartInfo() { FileName = emulator, Arguments = arguments, UseShellExecute = false, CreateNoWindow = true, RedirectStandardOutput = true, RedirectStandardError = true, WindowStyle = ProcessWindowStyle.Hidden, }; Log.LogMessage(MessageImportance.Low, $"Environment variables being passed to the tool:"); var p = new Process() { StartInfo = psi, }; if (!string.IsNullOrEmpty(AndroidSdkHome)) { psi.EnvironmentVariables ["ANDROID_HOME"] = AndroidSdkHome; Log.LogMessage(MessageImportance.Low, $"\tANDROID_HOME=\"{AndroidSdkHome}\""); } var sawError = new AutoResetEvent(false); DataReceivedEventHandler output = null; output = (o, e) => { Log.LogMessage(MessageImportance.Low, $"[emulator stdout] {e.Data}"); if (string.IsNullOrWhiteSpace(e.Data)) { return; } if (e.Data.StartsWith("Hax ram_size", StringComparison.Ordinal) && e.Data.EndsWith(" 0x0", StringComparison.Ordinal)) { Log.LogError("Emulator failed to start: ram_size is 0MB! Please re-install HAXM."); sawError.Set(); } if (e.Data.IndexOf("ERROR:", StringComparison.Ordinal) >= 0) { Log.LogError($"Emulator failed to start: {e.Data}"); sawError.Set(); } }; DataReceivedEventHandler error = null; error = (o, e) => { Log.LogMessage(MessageImportance.Low, $"[emulator stderr] {e.Data}"); if (string.IsNullOrWhiteSpace(e.Data)) { return; } if (e.Data.StartsWith("Failed to sync", StringComparison.Ordinal) || e.Data.Contains("Internal error")) { Log.LogError($"Emulator failed to start: {e.Data}"); Log.LogError($"Do you have another VM running on the machine? If so, please try exiting the VM and try again."); sawError.Set(); } if (e.Data.StartsWith("Unknown hax vcpu return", StringComparison.Ordinal)) { Log.LogError($"Emulator failed to start: `{e.Data}`. Please try again?"); sawError.Set(); } if (e.Data.IndexOf("ERROR:", StringComparison.Ordinal) >= 0 || e.Data.IndexOf(" failed ", StringComparison.Ordinal) >= 0) { Log.LogError($"Emulator failed to start: {e.Data}"); sawError.Set(); } }; p.OutputDataReceived += output; p.ErrorDataReceived += error; p.Start(); p.BeginOutputReadLine(); p.BeginErrorReadLine(); const int Timeout = 20 * 1000; int i = WaitHandle.WaitAny(new[] { sawError }, millisecondsTimeout: Timeout); if (i == 0 || Log.HasLoggedErrors) { p.Kill(); return; } p.CancelOutputRead(); p.CancelErrorRead(); p.OutputDataReceived -= output; p.ErrorDataReceived -= error; p.OutputDataReceived += WriteProcessOutputMessage; p.ErrorDataReceived += WriteProcessErrorMessage; p.BeginOutputReadLine(); p.BeginErrorReadLine(); EmulatorProcessId = p.Id; }
private AcoustId GetFingerprintUncached(string file) { if (IsSetup() && File.Exists(file)) { Process p = new Process(); p.StartInfo.FileName = _fpcalcPath; p.StartInfo.Arguments = $"{_fpcalcArgs} \"{file}\""; p.StartInfo.UseShellExecute = false; p.StartInfo.CreateNoWindow = true; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.RedirectStandardError = true; _logger.Trace("Executing {0} {1}", p.StartInfo.FileName, p.StartInfo.Arguments); StringBuilder output = new StringBuilder(); StringBuilder error = new StringBuilder(); // see https://stackoverflow.com/questions/139593/processstartinfo-hanging-on-waitforexit-why?lq=1 // this is most likely overkill... using (AutoResetEvent outputWaitHandle = new AutoResetEvent(false)) { using (AutoResetEvent errorWaitHandle = new AutoResetEvent(false)) { DataReceivedEventHandler outputHandler = (sender, e) => { if (e.Data == null) { outputWaitHandle.Set(); } else { output.AppendLine(e.Data); } }; DataReceivedEventHandler errorHandler = (sender, e) => { if (e.Data == null) { errorWaitHandle.Set(); } else { error.AppendLine(e.Data); } }; p.OutputDataReceived += outputHandler; p.ErrorDataReceived += errorHandler; p.Start(); p.BeginOutputReadLine(); p.BeginErrorReadLine(); if (p.WaitForExit(_fingerprintingTimeout) && outputWaitHandle.WaitOne(_fingerprintingTimeout) && errorWaitHandle.WaitOne(_fingerprintingTimeout)) { // Process completed. if (p.ExitCode != 0) { _logger.Warn($"fpcalc error: {error}"); return(null); } else { return(ParseFpcalcOutput(output.ToString())); } } else { // Timed out. Remove handlers to avoid object disposed error p.OutputDataReceived -= outputHandler; p.ErrorDataReceived -= errorHandler; _logger.Warn($"fpcalc timed out. {error}"); return(null); } } } } return(null); }
public static int ExecuteProcess(string FileName, string WorkingDir, string CommandLine, string Input, Action <string> OutputLine) { #if USE_NEW_PROCESS_JOBS using (ChildProcess NewProcess = new ChildProcess(FileName, WorkingDir, CommandLine, Input)) { string Line; while (NewProcess.TryReadLine(out Line)) { OutputLine(Line); } return(NewProcess.ExitCode); } #else using (Process ChildProcess = new Process()) { try { object LockObject = new object(); DataReceivedEventHandler OutputHandler = (x, y) => { if (y.Data != null) { lock (LockObject){ OutputLine(y.Data.TrimEnd()); } } }; ChildProcess.StartInfo.FileName = FileName; ChildProcess.StartInfo.Arguments = String.IsNullOrEmpty(CommandLine) ? "" : CommandLine; ChildProcess.StartInfo.UseShellExecute = false; ChildProcess.StartInfo.RedirectStandardOutput = true; ChildProcess.StartInfo.RedirectStandardError = true; ChildProcess.OutputDataReceived += OutputHandler; ChildProcess.ErrorDataReceived += OutputHandler; ChildProcess.StartInfo.RedirectStandardInput = Input != null; ChildProcess.StartInfo.CreateNoWindow = true; ChildProcess.StartInfo.StandardOutputEncoding = new System.Text.UTF8Encoding(false, false); ChildProcess.Start(); ChildProcess.BeginOutputReadLine(); ChildProcess.BeginErrorReadLine(); if (!String.IsNullOrEmpty(Input)) { ChildProcess.StandardInput.WriteLine(Input); ChildProcess.StandardInput.Close(); } // Busy wait for the process to exit so we can get a ThreadAbortException if the thread is terminated. It won't wait until we enter managed code // again before it throws otherwise. for (;;) { if (ChildProcess.WaitForExit(20)) { ChildProcess.WaitForExit(); break; } } return(ChildProcess.ExitCode); } finally { CloseHandle(JobObject); } } #endif }
private bool ExecuteBffFile(string BffFilePath) { string cacheArgument = ""; if (bEnableCaching) { switch (CacheMode) { case eCacheMode.ReadOnly: cacheArgument = "-cacheread"; break; case eCacheMode.WriteOnly: cacheArgument = "-cachewrite"; break; case eCacheMode.ReadWrite: cacheArgument = "-cache"; break; } } string distArgument = bEnableDistribution ? "-dist" : ""; //Interesting flags for FASTBuild: -nostoponerror, -verbose, -monitor (if FASTBuild Monitor Visual Studio Extension is installed!) // Yassine: The -clean is to bypass the FastBuild internal dependencies checks (cached in the fdb) as it could create some conflicts with UBT. // Basically we want FB to stupidly compile what UBT tells it to. string FBCommandLine = string.Format("-monitor -summary {0} {1} -ide -clean -config {2}", distArgument, cacheArgument, BffFilePath); ProcessStartInfo FBStartInfo = new ProcessStartInfo(string.IsNullOrEmpty(FBuildExePathOverride) ? "fbuild" : FBuildExePathOverride, FBCommandLine); FBStartInfo.UseShellExecute = false; FBStartInfo.WorkingDirectory = Path.Combine(UnrealBuildTool.EngineDirectory.MakeRelativeTo(DirectoryReference.GetCurrentDirectory()), "Source"); try { Process FBProcess = new Process(); FBProcess.StartInfo = FBStartInfo; FBStartInfo.RedirectStandardError = true; FBStartInfo.RedirectStandardOutput = true; FBProcess.EnableRaisingEvents = true; DataReceivedEventHandler OutputEventHandler = (Sender, Args) => { if (Args.Data != null) { Console.WriteLine(Args.Data); } }; FBProcess.OutputDataReceived += OutputEventHandler; FBProcess.ErrorDataReceived += OutputEventHandler; FBProcess.Start(); FBProcess.BeginOutputReadLine(); FBProcess.BeginErrorReadLine(); FBProcess.WaitForExit(); return(FBProcess.ExitCode == 0); } catch (Exception e) { Console.WriteLine("Exception launching fbuild process. Is it in your path?" + e.ToString()); return(false); } }
private static void ExecuteScript(string file) { var fi = new FileInfo(file); ProcessStartInfo processInfo; if (string.Equals(".ps1", fi.Extension, StringComparison.OrdinalIgnoreCase)) { processInfo = new ProcessStartInfo("PowerShell.exe", string.Format("-ExecutionPolicy RemoteSigned -File \"{0}\"", file)); } else { processInfo = new ProcessStartInfo(file); } processInfo.CreateNoWindow = true; processInfo.UseShellExecute = false; processInfo.RedirectStandardInput = true; processInfo.RedirectStandardError = true; processInfo.RedirectStandardOutput = true; DataReceivedEventHandler stdoutHandler = (object sender, DataReceivedEventArgs e) => { if (!string.IsNullOrWhiteSpace(e.Data)) { Trace(TraceEventType.Information, "{0}", e.Data); } }; DataReceivedEventHandler stderrHandler = (object sender, DataReceivedEventArgs e) => { if (!string.IsNullOrWhiteSpace(e.Data)) { Trace(TraceEventType.Error, "{0}", e.Data); } }; Trace(TraceEventType.Information, "Run post-deployment: \"{0}\" {1}", processInfo.FileName, processInfo.Arguments); var process = Process.Start(processInfo); var processName = process.ProcessName; var processId = process.Id; Trace(TraceEventType.Information, "Process {0}({1}) started", processName, processId); // hook stdout and stderr process.OutputDataReceived += stdoutHandler; process.BeginOutputReadLine(); process.ErrorDataReceived += stderrHandler; process.BeginErrorReadLine(); var timeout = (int)GetCommandTimeOut().TotalMilliseconds; if (!process.WaitForExit(timeout)) { process.Kill(); throw new TimeoutException(String.Format("Process {0}({1}) exceeded {2}ms timeout", processName, processId, timeout)); } process.WaitForExit(); if (process.ExitCode != 0) { throw new InvalidOperationException(String.Format("Process {0}({1}) exited with {2} exitcode.", processName, processId, process.ExitCode)); } Trace(TraceEventType.Information, "Process {0}({1}) executed successfully.", processName, processId); }
public void executeClasFile(string _classFileToExecute, DataReceivedEventHandler dataReceivedCallBack) { classFileToExecute = _classFileToExecute; executeClassFile(dataReceivedCallBack); }
void BuildSatelliteAssembly(string cultureName, List <string> files) { string assemblyPath = BuildAssemblyPath(cultureName); var info = new ProcessStartInfo(); var al = new Process(); string arguments = SetAlPath(info); var sb = new StringBuilder(arguments); sb.Append("/c:\"" + cultureName + "\" "); sb.Append("/t:lib "); sb.Append("/out:\"" + assemblyPath + "\" "); if (mainAssembly != null) { sb.Append("/template:\"" + mainAssembly.Location + "\" "); } string responseFilePath = assemblyPath + ".response"; using (FileStream fs = File.OpenWrite(responseFilePath)) { using (StreamWriter sw = new StreamWriter(fs)) { foreach (string f in files) { sw.WriteLine("/embed:\"" + f + "\" "); } } } sb.Append("@\"" + responseFilePath + "\""); info.Arguments = sb.ToString(); info.CreateNoWindow = true; info.UseShellExecute = false; info.RedirectStandardOutput = true; info.RedirectStandardError = true; al.StartInfo = info; var alOutput = new StringCollection(); var alMutex = new Mutex(); DataReceivedEventHandler outputHandler = (object sender, DataReceivedEventArgs args) => { if (args.Data != null) { alMutex.WaitOne(); alOutput.Add(args.Data); alMutex.ReleaseMutex(); } }; al.ErrorDataReceived += outputHandler; al.OutputDataReceived += outputHandler; // TODO: consider using asynchronous processes try { al.Start(); } catch (Exception ex) { throw new HttpException(String.Format("Error running {0}", al.StartInfo.FileName), ex); } Exception alException = null; int exitCode = 0; try { al.BeginOutputReadLine(); al.BeginErrorReadLine(); al.WaitForExit(); exitCode = al.ExitCode; } catch (Exception ex) { alException = ex; } finally { al.CancelErrorRead(); al.CancelOutputRead(); al.Close(); } if (exitCode != 0 || alException != null) { // TODO: consider adding a new type of compilation exception, // tailored for al CompilerErrorCollection errors = null; if (alOutput.Count != 0) { foreach (string line in alOutput) { if (!line.StartsWith("ALINK: error ", StringComparison.Ordinal)) { continue; } if (errors == null) { errors = new CompilerErrorCollection(); } int colon = line.IndexOf(':', 13); string errorNumber = colon != -1 ? line.Substring(13, colon - 13) : "Unknown"; string errorText = colon != -1 ? line.Substring(colon + 1) : line.Substring(13); errors.Add(new CompilerError(Path.GetFileName(assemblyPath), 0, 0, errorNumber, errorText)); } } throw new CompilationException(Path.GetFileName(assemblyPath), errors, null); } }