Java exec executeBashScriptWithParams(ArrayList script)

Here you can find the source of executeBashScriptWithParams(ArrayList script)

Description

execute Bash Script With Params

License

Apache License

Declaration

public static boolean executeBashScriptWithParams(ArrayList<String> script) 

Method Source Code


//package com.java2s;
/*/*from w  ww  . j a  va  2s  . c  om*/
 * 
This licence applies to all files in this repository unless otherwise specifically
stated inside of the file. 
    
 ---------------------------------------------------------------------------
   Copyright (c) 2016 AT&T Intellectual Property
    
   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.
 ---------------------------------------------------------------------------
    
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import java.util.ArrayList;

public class Main {
    public static boolean executeBashScriptWithParams(ArrayList<String> script) {
        try {
            ProcessBuilder pb = new ProcessBuilder(script);
            final Process process = pb.start();
            process.waitFor();
            InputStream is = process.getInputStream();
            InputStreamReader isr = new InputStreamReader(is);
            BufferedReader br = new BufferedReader(isr);
            String result = br.readLine();
            if (result == null)
                return false;
            if (result.equals("Running"))
                return true;
            else
                return false;
            /*         String s;
                 ArrayList<String> opText = new ArrayList<String>();
                   while ((s = br.readLine()) != null) {
               opText.add(s);
                       }
                   System.out.println(opText.size());
                   System.out.println(opText);
                
            */ } catch (IOException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return false;
    }
}

Related

  1. execute(Template template, Map rootMap)
  2. execute1(final String appPath)
  3. execute2(final String appPath)
  4. executeAndWait(String command)
  5. executeApplication(String filePath)
  6. executeBatFile(String batFile)
  7. executeCD(String dirPath)
  8. executeCmdCommand(String command)
  9. executeCmdForReader(String cmd)