/[classpath]/classpath/vm/reference/java/lang/VMProcess.java
ViewVC logotype

Diff of /classpath/vm/reference/java/lang/VMProcess.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2.2.3 by gnu_andrew, Wed Feb 16 01:11:42 2005 UTC revision 1.2.2.4 by tromey, Wed May 4 22:59:44 2005 UTC
# Line 43  import java.io.InputStream; Line 43  import java.io.InputStream;
43  import java.io.OutputStream;  import java.io.OutputStream;
44  import java.util.HashMap;  import java.util.HashMap;
45  import java.util.LinkedList;  import java.util.LinkedList;
46    import java.util.List;
47    import java.util.Map;
48    
49  /**  /**
50   * Represents one external process. Each instance of this class is in   * Represents one external process. Each instance of this class is in
# Line 92  final class VMProcess extends Process Line 94  final class VMProcess extends Process
94    InputStream stdout;                          // process output stream    InputStream stdout;                          // process output stream
95    InputStream stderr;                          // process error stream    InputStream stderr;                          // process error stream
96    int exitValue;                               // process exit value    int exitValue;                               // process exit value
97      boolean redirect;                            // redirect stderr -> stdout
98    
99    //    //
100    // Dedicated thread that does all the fork()'ing and wait()'ing    // Dedicated thread that does all the fork()'ing and wait()'ing
# Line 196  final class VMProcess extends Process Line 199  final class VMProcess extends Process
199          {          {
200            try            try
201              {              {
202                process.nativeSpawn(process.cmd, process.env, process.dir);                process.nativeSpawn(process.cmd, process.env, process.dir,
203                                      process.redirect);
204                process.state = RUNNING;                process.state = RUNNING;
205                activeMap.put(new Long(process.pid), process);                activeMap.put(new Long(process.pid), process);
206              }              }
# Line 215  final class VMProcess extends Process Line 219  final class VMProcess extends Process
219    }    }
220    
221    // Constructor    // Constructor
222    private VMProcess(String[] cmd, String[] env, File dir) throws IOException    private VMProcess(String[] cmd, String[] env, File dir, boolean redirect)
223        throws IOException
224    {    {
225            
226      // Initialize this process      // Initialize this process
# Line 223  final class VMProcess extends Process Line 228  final class VMProcess extends Process
228      this.cmd = cmd;      this.cmd = cmd;
229      this.env = env;      this.env = env;
230      this.dir = dir;      this.dir = dir;
231        this.redirect = redirect;
232        
233      // Add process to the new process work list and wakeup processThread      // Add process to the new process work list and wakeup processThread
234      synchronized (workList)      synchronized (workList)
# Line 275  final class VMProcess extends Process Line 281  final class VMProcess extends Process
281    
282    // Invoked by native code (from nativeSpawn()) to record process info.    // Invoked by native code (from nativeSpawn()) to record process info.
283    private void setProcessInfo(OutputStream stdin,    private void setProcessInfo(OutputStream stdin,
284                   InputStream stdout, InputStream stderr, long pid)                                InputStream stdout, InputStream stderr, long pid)
285    {    {
286      this.stdin = stdin;      this.stdin = stdin;
287      this.stdout = stdout;      this.stdout = stdout;
288      this.stderr = stderr;      if (stderr == null)
289          this.stderr = new InputStream()
290            {
291              public int read() throws IOException
292              {
293                return -1;
294              }
295            };
296        else
297          this.stderr = stderr;
298      this.pid = pid;      this.pid = pid;
299    }    }
300    
# Line 288  final class VMProcess extends Process Line 303  final class VMProcess extends Process
303     */     */
304    static Process exec(String[] cmd, String[] env, File dir) throws IOException    static Process exec(String[] cmd, String[] env, File dir) throws IOException
305    {    {
306      return new VMProcess(cmd, env, dir);      return new VMProcess(cmd, env, dir, false);
307      }
308    
309      static Process exec(List<String> cmd, Map<String, String> env,
310                          File dir, boolean redirect) throws IOException
311      {
312        String[] acmd = cmd.toArray(new String[cmd.size()]);
313        String[] aenv = new String[env.size()];
314    
315        int i = 0;
316        for (Map.Entry<String, String> entry : env.entrySet())
317          aenv[i++] = entry.getKey() + "=" + entry.getValue();
318    
319        return new VMProcess(acmd, aenv, dir, redirect);
320    }    }
321    
322    public OutputStream getOutputStream()    public OutputStream getOutputStream()
# Line 347  final class VMProcess extends Process Line 375  final class VMProcess extends Process
375     *     *
376     * @throws IOException if the O/S process could not be created.     * @throws IOException if the O/S process could not be created.
377     */     */
378    native void nativeSpawn(String[] cmd, String[] env, File dir)    native void nativeSpawn(String[] cmd, String[] env, File dir,
379                              boolean redirect)
380      throws IOException;      throws IOException;
381    
382    /**    /**

Legend:
Removed from v.1.2.2.3  
changed lines
  Added in v.1.2.2.4

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26