Exemplo n.º 1
0
 /// <summary>Execute a command and return a single line of output as a String</summary>
 /// <param name="dir">Working directory for the command</param>
 /// <param name="command">as component array</param>
 /// <param name="encoding"></param>
 /// <returns>the one-line output of the command</returns>
 protected internal static string ReadPipe(FilePath dir, string[] command, string
                                           encoding)
 {
     try
     {
         SystemProcess  p        = Runtime.GetRuntime().Exec(command, null, dir);
         BufferedReader lineRead = new BufferedReader(new InputStreamReader(p.GetInputStream
                                                                                (), encoding));
         string r = null;
         try
         {
             r = lineRead.ReadLine();
         }
         finally
         {
             p.GetOutputStream().Close();
             p.GetErrorStream().Close();
             lineRead.Close();
         }
         for (; ;)
         {
             try
             {
                 if (p.WaitFor() == 0 && r != null && r.Length > 0)
                 {
                     return(r);
                 }
                 break;
             }
             catch (Exception)
             {
             }
         }
     }
     catch (IOException e)
     {
         // Stop bothering me, I have a zombie to reap.
         if (SystemReader.GetInstance().GetProperty("jgit.fs.debug") != null)
         {
             System.Console.Error.WriteLine(e);
         }
     }
     // Ignore error (but report)
     return(null);
 }
        /// <summary>Run a hook script in the repository, returning the exit status.</summary>
        /// <remarks>Run a hook script in the repository, returning the exit status.</remarks>
        /// <param name="db">repository the script should see in GIT_DIR environment</param>
        /// <param name="hook">
        /// path of the hook script to execute, must be executable file
        /// type on this platform
        /// </param>
        /// <param name="args">arguments to pass to the hook script</param>
        /// <returns>exit status code of the invoked hook</returns>
        /// <exception cref="System.IO.IOException">the hook could not be executed</exception>
        /// <exception cref="System.Exception">the caller was interrupted before the hook completed
        ///     </exception>
        protected internal virtual int RunHook(Repository db, FilePath hook, params string
                                               [] args)
        {
            string[] argv = new string[1 + args.Length];
            argv[0] = hook.GetAbsolutePath();
            System.Array.Copy(args, 0, argv, 1, args.Length);
            IDictionary <string, string> env = CloneEnv();

            env.Put("GIT_DIR", db.Directory.GetAbsolutePath());
            PutPersonIdent(env, "AUTHOR", author);
            PutPersonIdent(env, "COMMITTER", committer);
            FilePath      cwd = db.WorkTree;
            SystemProcess p   = Runtime.GetRuntime().Exec(argv, ToEnvArray(env), cwd);

            p.GetOutputStream().Close();
            p.GetErrorStream().Close();
            p.GetInputStream().Close();
            return(p.WaitFor());
        }
Exemplo n.º 3
0
 /// <summary>Execute a command and return a single line of output as a String</summary>
 /// <param name="dir">Working directory for the command</param>
 /// <param name="command">as component array</param>
 /// <param name="encoding"></param>
 /// <returns>the one-line output of the command</returns>
 protected internal static string ReadPipe(FilePath dir, string[] command, string
                                           encoding)
 {
     try
     {
         SystemProcess  p        = Runtime.GetRuntime().Exec(command, null, dir);
         BufferedReader lineRead = new BufferedReader(new InputStreamReader(p.GetInputStream
                                                                                (), encoding));
         string r = null;
         try
         {
             r = lineRead.ReadLine();
         }
         finally
         {
             p.GetOutputStream().Close();
             p.GetErrorStream().Close();
             lineRead.Close();
         }
         for (; ;)
         {
             try
             {
                 if (p.WaitFor() == 0 && r != null && r.Length > 0)
                 {
                     return(r);
                 }
                 break;
             }
             catch (Exception)
             {
             }
         }
     }
     catch (IOException)
     {
     }
     // Stop bothering me, I have a zombie to reap.
     // ignore
     return(null);
 }
Exemplo n.º 4
0
Arquivo: FS.cs Projeto: Gearset/ngit
        /// <summary>Execute a command and return a single line of output as a String</summary>
        /// <param name="dir">Working directory for the command</param>
        /// <param name="command">as component array</param>
        /// <param name="encoding"></param>
        /// <returns>the one-line output of the command</returns>
        protected internal static string ReadPipe(FilePath dir, string[] command, string
                                                  encoding)
        {
            bool debug = System.Boolean.Parse(SystemReader.GetInstance().GetProperty("jgit.fs.debug"
                                                                                     ));

            try
            {
                if (debug)
                {
                    System.Console.Error.WriteLine("readpipe " + Arrays.AsList(command) + "," + dir);
                }
                SystemProcess  p        = Runtime.GetRuntime().Exec(command, null, dir);
                BufferedReader lineRead = new BufferedReader(new InputStreamReader(p.GetInputStream
                                                                                       (), encoding));
                p.GetOutputStream().Close();
                AtomicBoolean  gooblerFail = new AtomicBoolean(false);
                Sharpen.Thread gobbler     = new _Thread_300(p, debug, gooblerFail);
                // ignore
                // Just print on stderr for debugging
                // Just print on stderr for debugging
                gobbler.Start();
                string r = null;
                try
                {
                    r = lineRead.ReadLine();
                    if (debug)
                    {
                        System.Console.Error.WriteLine("readpipe may return '" + r + "'");
                        System.Console.Error.WriteLine("(ignoring remaing output:");
                    }
                    string l;
                    while ((l = lineRead.ReadLine()) != null)
                    {
                        if (debug)
                        {
                            System.Console.Error.WriteLine(l);
                        }
                    }
                }
                finally
                {
                    p.GetErrorStream().Close();
                    lineRead.Close();
                }
                for (; ;)
                {
                    try
                    {
                        int rc = p.WaitFor();
                        gobbler.Join();
                        if (rc == 0 && r != null && r.Length > 0 && !gooblerFail.Get())
                        {
                            return(r);
                        }
                        if (debug)
                        {
                            System.Console.Error.WriteLine("readpipe rc=" + rc);
                        }
                        break;
                    }
                    catch (Exception)
                    {
                    }
                }
            }
            catch (IOException e)
            {
                // Stop bothering me, I have a zombie to reap.
                if (debug)
                {
                    System.Console.Error.WriteLine(e);
                }
            }
            // Ignore error (but report)
            if (debug)
            {
                System.Console.Error.WriteLine("readpipe returns null");
            }
            return(null);
        }