summaryrefslogtreecommitdiffstats
path: root/appmarket-utils/src/main/java/app/market/utils/RuntimeUtil.java
diff options
context:
space:
mode:
Diffstat (limited to 'appmarket-utils/src/main/java/app/market/utils/RuntimeUtil.java')
-rw-r--r--appmarket-utils/src/main/java/app/market/utils/RuntimeUtil.java66
1 files changed, 66 insertions, 0 deletions
diff --git a/appmarket-utils/src/main/java/app/market/utils/RuntimeUtil.java b/appmarket-utils/src/main/java/app/market/utils/RuntimeUtil.java
new file mode 100644
index 0000000..195b7cc
--- /dev/null
+++ b/appmarket-utils/src/main/java/app/market/utils/RuntimeUtil.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2019 TOYOTA MOTOR CORPORATION
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package app.market.utils;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+
+public class RuntimeUtil {
+/**
+ * Execute Command of Linux Shell
+ * @param cmd
+ * @return Execute's result
+ */
+ public static boolean linuxCmdExec(String cmd) {
+ boolean ret = false;
+
+ try {
+ Process process = Runtime.getRuntime().exec(cmd);
+ BufferedReader stdoutReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
+ BufferedReader stderrReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
+ String line;
+
+ while ((line = stdoutReader.readLine()) != null) {
+ System.out.println(line);
+ }
+
+ while ((line = stderrReader.readLine()) != null) {
+ System.out.println(line);
+ }
+
+ int exitVal = process.waitFor();
+
+ System.out.println("Process exit value is " + exitVal);
+ if(exitVal != 0) {
+ return ret;
+ }
+
+ ret = true;
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ } catch (SecurityException e) {
+ e.printStackTrace();
+ } catch (NullPointerException e) {
+ e.printStackTrace();
+ } catch (IndexOutOfBoundsException e) {
+ e.printStackTrace();
+ }
+ return ret;
+ }
+}