Exemple #1
0
        public void TestDefaultProcessorBuilderFactory_customExecutable()
        {
            ProcessBuilder processBuilder =
                DockerClient.DefaultProcessBuilderFactory("docker-executable", ImmutableDictionary.Create <string, string>())
                    (new[] { "sub", "command" });

            Assert.AreEqual("docker-executable sub command", processBuilder.Command());
            CollectionAssert.AreEquivalent(
                Environment.GetEnvironmentVariables()
                .Cast <DictionaryEntry>()
                .ToDictionary(e => e.Key.ToString(), e => e.Value.ToString()),
                processBuilder.GetEnvironment());
        }
 /// <summary>Start the process defined by the ProcessBuilder, and run until complete.</summary>
 /// <param name="builder">The ProcessBuilder defining the process to run.</param>
 /// <param name="output">
 /// Where the process output should be written. If null, the
 /// process output will be written to System.out.
 /// </param>
 /// <param name="error">
 /// Where the process error output should be written. If null,
 /// the process error output will written to System.err.
 /// </param>
 public static void Run(ProcessBuilder builder, TextWriter output, TextWriter error)
 {
     try
     {
         Process process = builder.Start();
         Consume(process, output, error);
         int result = process.WaitFor();
         if (result != 0)
         {
             string msg = "process %s exited with value %d";
             throw new SystemUtils.ProcessException(string.Format(msg, builder.Command(), result));
         }
     }
     catch (Exception e)
     {
         throw new SystemUtils.ProcessException(e);
     }
 }
        /// <exception cref="System.IO.IOException"/>
        public BZip2PipedOutputStream(string filename, OutputStream err)
        {
            string bzip2 = Runtime.GetProperty("bzip2", "bzip2");
            string cmd   = bzip2;
            // + " > " + filename;
            //log.info("getBZip2PipedOutputStream: Running command: "+cmd);
            ProcessBuilder pb = new ProcessBuilder();

            pb.Command(cmd);
            this.process  = pb.Start();
            this.filename = filename;
            OutputStream outStream = new FileOutputStream(filename);

            errWriter  = new PrintWriter(new BufferedWriter(new OutputStreamWriter(err)));
            outGobbler = new ByteStreamGobbler("Output stream gobbler: " + cmd + " " + filename, process.GetInputStream(), outStream);
            errGobbler = new StreamGobbler(process.GetErrorStream(), errWriter);
            outGobbler.Start();
            errGobbler.Start();
        }