Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static Process _proc;
- static Terminal() {
- _proc = new Process();
- _proc.EnableRaisingEvents = true;
- _proc.OutputDataReceived += (s, e) => Console.WriteLine(e.Data);
- _proc.ErrorDataReceived += (s,e) => Console.WriteLine(e.Data);
- }
- public static void Run(string command) {
- _proc.StartInfo = new ProcessStartInfo() {
- FileName = "/bin/bash",
- Arguments = $"-c \"{command}\"",
- UseShellExecute = false,
- RedirectStandardOutput = true,
- RedirectStandardError = true,
- RedirectStandardInput = true,
- };
- _proc.Start();
- while(!_proc.StandardOutput.EndOfStream){
- Console.WriteLine(_proc.StandardOutput.ReadLine());
- }
- }
- public static string Execute(string command) {
- _proc.StartInfo = new ProcessStartInfo() {
- FileName = "/bin/bash",
- Arguments = $"-c \"{command}\"",
- UseShellExecute = false,
- RedirectStandardOutput = true,
- RedirectStandardError = true,
- RedirectStandardInput = true,
- };
- _proc.Start();
- StringBuilder strgBuilder = new StringBuilder();
- while(!_proc.StandardOutput.EndOfStream){
- strgBuilder.AppendLine(_proc.StandardOutput.ReadLine());
- }
- return strgBuilder.ToString();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement