private Process RunInterceptor(string name, Dictionary <string, string> data, InterceptorType interceptorType) { string typeInterceptor = interceptorType.ToString(); //string replace = ReplaceForInterceptor(interceptorType); var pi = new ProcessStartInfo(FullPath); string wd = FolderToExecute; if (string.IsNullOrWhiteSpace(wd)) { wd = Path.GetDirectoryName(Path.GetFullPath(Name)); } string arguments = Arguments; if (string.IsNullOrWhiteSpace(arguments)) { arguments = ReplaceForInterceptor(interceptorType); } foreach (var item in data) { arguments = arguments.Replace(item.Key, item.Value); } pi.Arguments = arguments; //Console.WriteLine($"!!!!!!!!!!!!start {pi.FileName} with {arguments}"); pi.RedirectStandardError = InterceptOutput; pi.RedirectStandardOutput = InterceptOutput; pi.WorkingDirectory = wd; pi.UseShellExecute = !InterceptOutput; pi.CreateNoWindow = InterceptOutput; var p = new Process() { StartInfo = pi }; p.EnableRaisingEvents = InterceptOutput; p.Start(); if (InterceptOutput) { p.BeginOutputReadLine(); p.BeginErrorReadLine(); p.OutputDataReceived += (sender, args) => { Console.WriteLine($"Interceptor {typeInterceptor}: {name} => {args.Data}"); }; p.ErrorDataReceived += (sender, args) => { Console.WriteLine($"Interceptor {typeInterceptor}: {name} ERROR => {args.Data}"); }; p.Exited += (sender, args) => { Console.WriteLine($"Interceptor {typeInterceptor}: {name} exited "); }; } return(p); }
private string ReplaceForInterceptor(InterceptorType interceptorType) { switch (interceptorType) { case InterceptorType.LineInterceptor: return("{line}"); case InterceptorType.FinishInterceptor: return("{exitCode}"); case InterceptorType.TimerInterceptor: return(null); default: throw new ArgumentException($"Cannot find {interceptorType.ToString()}"); } }
public static bool Start(Computer cpu, RecordFile cfile, InterceptorType type, bool rmCfile, string bcIP, int bcPort, string path) { if (Initialize(cpu)) { string command = String.Format("cd dev_utilities && ./interceptor.sh -r {0} {1} {2} {3} {4} {5} {6} {7} {8} {9} {10} {11} &", type.ToString(), cfile.ID, cfile.Count, cfile.Band, cfile.ARFCN, cfile.Frequency, cfile.SampleRate, cfile.Rx, rmCfile ? 1 : 0, bcIP, bcPort, path); shellStream.WriteLine(command); #if (DEBUG) string feedback = shellStream.Expect("root", new TimeSpan(0, 0, 10)); #endif sshClient.Disconnect(); return(true); } else { return(false); } }