/* * Runs a program with the given absolute path name, it's arguments and optionally * the command name that was entered by a user. */ private Process RunProgram(string programName, string arguments, string enteredName = null) { // Create new process, set info Process running = new Process(); running.StartInfo.UseShellExecute = false; running.StartInfo.FileName = programName; running.StartInfo.Arguments = arguments; try { running.Start(); } catch (InvalidOperationException f) { console.WriteLine("Process somehow had no file name - Terminating..."); console.WriteLine(f.Message); Environment.Exit(1); } catch (Win32Exception f) { if (enteredName == null) { this.console.WriteLine("Program '" + programName + "' not an executable file."); } else { this.console.WriteLine("Program '" + enteredName + "' not an executable file."); } this.console.WriteLine(f.Message); return(null); } return(running); }
private static void ChangeDirectory(List <string> args, ShellConsole io) { // cd does nothing for no arguments if (args.Count == 0) { return; } Debug.WriteLine(args[0]); // Attempt to change directory, print error if not possible try { Directory.SetCurrentDirectory(args[0]); } catch (FileNotFoundException f) { io.WriteLine(f.Message); } catch (DirectoryNotFoundException d) { io.WriteLine(d.Message); } }