0

i have problem with this code i use the CLC (cloud fondry)to deplyer the application in the cloud my code is

public class cmd1 {

public static void main(String[] args) throws IOException, InterruptedException {
    String[] command =
        {
            "cmd",
        };
        Process p = Runtime.getRuntime().exec(command);
        new Thread(new SyncPipe(p.getErrorStream(), System.err)).start();
        new Thread(new SyncPipe(p.getInputStream(), System.out)).start();
        PrintWriter stdin = new PrintWriter(p.getOutputStream());
        stdin.println("dir c:\\ /A /Q");  //ca march bien 


        stdin.println("cf login");        //ca march    

        stdin.println("hakimguettaoui@gmail.com");   //ici si j'ai fait un login il me demander Email et mot de pass mais il me 
                                                     // donnée un pb 
        stdin.println("");


        // write any other commands you want here
        stdin.close();
        int returnCode = p.waitFor();
        System.out.println("Return code = " + returnCode);

}

}

class SyncPipe implements Runnable {


public SyncPipe(InputStream istrm, OutputStream ostrm) {
 istrm_ = istrm;
 ostrm_ = ostrm;}
 public void run() {
 try
 {
     final byte[] buffer = new byte[1024];
     for (int length = 0; (length = istrm_.read(buffer)) != -1; )
     {
         ostrm_.write(buffer, 0, length);
     }
 }catch (Exception e)
 {
     e.printStackTrace();
 } } private final OutputStream ostrm_; private final InputStream istrm_;

}

all of command is work but if i use cf login is work but the authentification is not work lock the err enter image description here

1 Answers1

0

You're doing it correctly, separate Threads for STDOUT and STDERR. After using Runtime for years, I switched to ProcessBuilder...Maybe switch to ProcessBuilder. See the following posts on this :

Java Runtime OR Processbuilder OR Other

Java - ProcessBuilder command arguments with spaces and double-quotes fails

Community
  • 1
  • 1
lincolnadym
  • 909
  • 1
  • 12
  • 29