0

I am executing a shell script from a java program, in that shell script I am connecting to a datamart server and executing the resmgr command but I am unable to get output of resmgr command, If I run the same command from command line I am able getting the output.

Shell Script:

#!/bin/bash
source /opt/datamart/dataMart.env
/opt/datamart/bin/resmgr -export fgp -colNames "nName frm.dbIndex" -filter "npath($1) frm.name($2)" -noHead -sep ','

Java Program:

import java.io.*;
import java.util.*;

public class Test {

    public static void main(String argsm[]) throws IOException, InterruptedException {
        String cmd="./getDBIndex1.sh ~AP~Generic~Universal~Throughput \"Inbound Volume (octets)\"";
        Runtime run = Runtime.getRuntime();
        Process pr = run.exec(cmd);
        pr.waitFor();
        BufferedReader buf = new BufferedReader(new InputStreamReader(pr.getInputStream()));
        String line = "";
        while ((line=buf.readLine())!=null) {
            System.out.println(line);
        }
    }
}
morgano
  • 17,210
  • 10
  • 45
  • 56

1 Answers1

0

I guess that's because the String cmd is not interpreted by run.exec() as you expect. Try changing your string cmd to an array of Strings. i. e. just change the line:

String cmd="./getDBIndex1.sh ~AP~Generic~Universal~Throughput \"Inbound Volume (octets)\""

for this:

String[] cmd= new String[] {"./getDBIndex1.sh", "~AP~Generic~Universal~Throughput", "Inbound Volume (octets)"};

and just leave the rest of the code unchanged. And also check that the script is in the current working directory

morgano
  • 17,210
  • 10
  • 45
  • 56