Home | History | Annotate | Download | only in term
      1 /*
      2  * Copyright (C) 2007 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.term;
     18 
     19 import java.io.FileDescriptor;
     20 
     21 /**
     22  * Utility methods for creating and managing a subprocess.
     23  * <p>
     24  * Note: The native methods access a package-private
     25  * java.io.FileDescriptor field to get and set the raw Linux
     26  * file descriptor. This might break if the implementation of
     27  * java.io.FileDescriptor is changed.
     28  */
     29 
     30 public class Exec
     31 {
     32     static {
     33         System.loadLibrary("term");
     34     }
     35 
     36     /**
     37      * Create a subprocess. Differs from java.lang.ProcessBuilder in
     38      * that a pty is used to communicate with the subprocess.
     39      * <p>
     40      * Callers are responsible for calling Exec.close() on the returned
     41      * file descriptor.
     42      *
     43      * @param cmd The command to execute
     44      * @param arg0 The first argument to the command, may be null
     45      * @param arg1 the second argument to the command, may be null
     46      * @param processId A one-element array to which the process ID of the
     47      * started process will be written.
     48      * @return the file descriptor of the started process.
     49      *
     50      */
     51     public static native FileDescriptor createSubprocess(
     52         String cmd, String arg0, String arg1, int[] processId);
     53 
     54     /**
     55      * Set the widow size for a given pty. Allows programs
     56      * connected to the pty learn how large their screen is.
     57      */
     58     public static native void setPtyWindowSize(FileDescriptor fd,
     59        int row, int col, int xpixel, int ypixel);
     60 
     61     /**
     62      * Causes the calling thread to wait for the process associated with the
     63      * receiver to finish executing.
     64      *
     65      * @return The exit value of the Process being waited on
     66      *
     67      */
     68     public static native int waitFor(int processId);
     69 
     70     /**
     71      * Close a given file descriptor.
     72      */
     73     public static native void close(FileDescriptor fd);
     74 }
     75 
     76