• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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.googlecode.android_scripting;
18 
19 import java.io.FileDescriptor;
20 
21 /**
22  * Tools for executing commands.
23  */
24 public class Exec {
25   /**
26    * @param cmd
27    *          The command to execute
28    * @param arg0
29    *          The first argument to the command, may be null
30    * @param arg1
31    *          the second argument to the command, may be null
32    * @return the file descriptor of the started process.
33    *
34    */
createSubprocess(String command, String[] arguments, String[] environmentVariables, String workingDirectory)35   public static FileDescriptor createSubprocess(String command, String[] arguments,
36       String[] environmentVariables, String workingDirectory) {
37     return createSubprocess(command, arguments, environmentVariables, workingDirectory, null);
38   }
39 
40   /**
41    * @param cmd
42    *          The command to execute
43    * @param arguments
44    *          Array of arguments, may be null
45    * @param environmentVariables
46    *          Array of environment variables, may be null
47    * @param processId
48    *          A one-element array to which the process ID of the started process will be written.
49    * @return the file descriptor of the opened process's psuedo-terminal.
50    *
51    */
createSubprocess(String command, String[] arguments, String[] environmentVariables, String workingDirectory, int[] processId)52   public static native FileDescriptor createSubprocess(String command, String[] arguments,
53       String[] environmentVariables, String workingDirectory, int[] processId);
54 
setPtyWindowSize(FileDescriptor fd, int row, int col, int xpixel, int ypixel)55   public static native void setPtyWindowSize(FileDescriptor fd, int row, int col, int xpixel,
56       int ypixel);
57 
58   /**
59    * Causes the calling thread to wait for the process associated with the receiver to finish
60    * executing.
61    *
62    * @return The exit value of the Process being waited on
63    *
64    */
waitFor(int processId)65   public static native int waitFor(int processId);
66 
67   static {
68     System.loadLibrary("com_googlecode_android_scripting_Exec");
69   }
70 }
71