Example #1
0
 public java.lang.Process exec(String[] cmdArray, String[] env, java.io.File dir)
 {
     java.lang.Process p = new java.lang.Process();
     p.StartInfo.WorkingDirectory = (null != dir) ? dir.toString() : SystemJ.getProperty("user.dir");
     p.StartInfo.FileName         = cmdArray[0];
     for (int i = 0; i < env.Length; i++)
     {
         String [] keyValue = env [i].Split('=');
         p.StartInfo.EnvironmentVariables.Add(keyValue[0], keyValue[1]);
     }
     for (int i = 1; i < cmdArray.Length; i++)
     {
         p.StartInfo.Arguments.Insert(i - 1, cmdArray[i]);
     }
     p.StartInfo.UseShellExecute        = true;
     p.StartInfo.RedirectStandardOutput = true;
     p.StartInfo.RedirectStandardInput  = true;
     p.StartInfo.RedirectStandardError  = true;
     p.Start();
     return(p);
 }
Example #2
0
        /**
         * Starts a new process based on the current state of this process builder.
         *
         * @return the new {@code Process} instance.
         * @throws NullPointerException
         *             if any of the elements of {@link #command()} is {@code null}.
         * @throws IndexOutOfBoundsException
         *             if {@link #command()} is empty.
         * @throws SecurityException
         *             if {@link SecurityManager#checkExec(String)} doesn't allow
         *             process creation.
         * @throws IOException
         *             if an I/O error happens.
         */
        public Process start()//throws IOException {
        {
            if (commandJ.isEmpty())
            {
                throw new IndexOutOfBoundsException();
            }
            String[] cmdArray = new String[commandJ.size()];
            for (int i = 0; i < cmdArray.Length; i++)
            {
                if ((cmdArray[i] = commandJ.get(i)) == null)
                {
                    throw new NullPointerException();
                }
            }
            String[] envArray = new String[environmentJ.size()];
            int      i2       = 0;

            /*
             * foreach (Map.Entry<String, String> entry in environmentJ.entrySet()) {
             * envArray[i2++] = entry.getKey() + "=" + entry.getValue(); //$NON-NLS-1$
             * }
             */
            java.util.Iterator <String> it = environmentJ.keySet().iterator();
            while (it.hasNext())
            {
                String key   = it.next();
                String value = environmentJ.get(key);
                envArray[i2++] = key + "=" + value;
            }

            java.lang.Process process = Runtime.getRuntime().exec(cmdArray, envArray,
                                                                  directoryJ);

            // TODO implement support for redirectErrorStream
            return(process);
        }
Example #3
0
 public java.lang.Process exec(String[] cmdArray, String[] env, java.io.File dir)
 {
     java.lang.Process p = new java.lang.Process();
     p.StartInfo.WorkingDirectory = (null!=dir) ? dir.toString () : SystemJ.getProperty("user.dir");
     p.StartInfo.FileName = cmdArray[0];
     for (int i = 0; i < env.Length; i++) {
         String [] keyValue = env [i].Split ('=');
         p.StartInfo.EnvironmentVariables.Add (keyValue[0],keyValue[1]);
     }
     for (int i = 1; i < cmdArray.Length; i++) {
         p.StartInfo.Arguments.Insert(i - 1, cmdArray[i]);
     }
     p.StartInfo.UseShellExecute = true;
     p.StartInfo.RedirectStandardOutput = true;
     p.StartInfo.RedirectStandardInput = true;
     p.StartInfo.RedirectStandardError = true;
     p.Start();
     return p;
 }