Esempio n. 1
0
File: Cmd.cs Progetto: neiz/Wish
 public string Execute(RunnerArgs args)
 {
     var process = new Process
                       {
                           StartInfo = new ProcessStartInfo("cmd", "/c " + args.Script)
                                           {
                                               RedirectStandardOutput = true,
                                               RedirectStandardError = true,
                                               CreateNoWindow = true,
                                               UseShellExecute = false,
                                               WorkingDirectory = WorkingDirectory
                                           }
                       };
     process.Start();
     /* can't read both error and output
      * see: http://msdn.microsoft.com/en-us/library/system.diagnostics.process.standarderror(v=vs.71).aspx
      * ctrl + f -> A similar problem
      * Both error and output would need thier own threads
      */
     //var error = process.StandardError.ReadToEnd();
     //if (!string.IsNullOrEmpty(error)) return error;
     var output = process.StandardOutput.ReadToEnd();
     if(!process.WaitForExit(1000))
     {
         process.Kill();
         return "An error has occurred";
     }
     _cmdDirectoryManager.UpdateWorkingDirectory(args.Script);
     return output;
 }
Esempio n. 2
0
 public string Execute(RunnerArgs args)
 {
     _pipeline = Runspace.CreatePipeline();
     _pipeline.Commands.AddScript(args.Script);
     _pipeline.Commands.Add("Out-String");
     Collection<PSObject> psObjects;
     try
     {
         psObjects = _pipeline.Invoke();
     } catch(Exception e)
     {
         return e.Message;
     }
     if(_pipeline.Error.Count > 0)
     {
         var firstOrDefault = _pipeline.Error.ReadToEnd().FirstOrDefault();
         if (firstOrDefault != null)
         {
             return firstOrDefault.ToString();
         }
     }
     if(_pipeline.Output.Count > 0)
     {
         var firstOrDefault = _pipeline.Output.ReadToEnd().FirstOrDefault();
         if (firstOrDefault != null)
         {
             return firstOrDefault.ToString();
         }
     }
     var sb = new StringBuilder();
     foreach (var psObject in psObjects)
     {
         sb.AppendLine(psObject.ToString());
     }
     return sb.ToString();
 }
Esempio n. 3
0
 public string Execute(RunnerArgs args)
 {
     throw new System.NotImplementedException();
 }
Esempio n. 4
0
 public void SecondRead()
 {
     // super fragile, will break with any change to file structure
     var text = ExecuteLs();
     text += new RunnerArgs { Script = "ls" };
     var comm = _repl.Read(text);
     Assert.AreEqual(new RunnerArgs { Script = "ls" }, comm.Function.Name);
 }