Insert cqlsh Copy command after opening cqlsh.bat from cmd using java

Viewed 143

I am not able to insert the CQLSH command -COPY after opening CQLSH.bat from java code on windows machine. Command prompt gets opened and CQLSH> prompt occurs but not taking any command sent from Outputstream. I tried the possible solution already discussed.But its not working for me. below is the code I am trying

 try {

           String sysEnvStr = System.getenv("CASSANDRA_HOME");//having path as  C:\Program Files\apache-cassandra-3.11.2

           Process p = Runtime.getRuntime().exec("cmd /k start cqlsh.bat", null, new File(sysEnvStr + "\\bin"));

           BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
           BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
           BufferedWriter output = new BufferedWriter(new OutputStreamWriter(p.getOutputStream()));

           output.write("COPY mydb.processed_data FROM processed_file.csv");
           output.flush();
           output.close();

           // read the output from the command
           String s = "";

           while ((s = stdInput.readLine()) != null) {
              System.out.println(s);
           }
           while ((s = stdError.readLine()) != null) {
              System.out.println("Std ERROR : " + s);
           }
           int returnCode = p.waitFor();
           System.out.println("Return code = " + returnCode);

        } catch (IOException ex) {
            Logger.getLogger(TempTest.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InterruptedException ex) {
            Logger.getLogger(TempTest.class.getName()).log(Level.SEVERE, null, ex);
        }
0 Answers
Related