The script works fine but stop when it ends...
Here's the code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.lang.*;
public class IOD extends JFrame implements ActionListener {
File f;
JLabel img;
JScrollPane sc;
private ImageIcon createImageIcon(String path) {
try {
return new ImageIcon(path);
}
catch (Exception e) {
System.out.println(e.toString());
return null;
}
}
public void actionPerformed (ActionEvent ae) {
JButton jb = (JButton) ae.getSource();
if ( jb.getLabel().equals("Load image") ) { // Load Button
try {
JFileChooser fc = new JFileChooser();
fc.showDialog(this, "Choose Image");
f = fc.getSelectedFile();
try {
img.setVisible(false);
sc.setVisible(false);
}
catch (Exception ex) {}
img = new JLabel(createImageIcon(f.getAbsolutePath()));
sc = new JScrollPane(img);
this.getContentPane().add(sc, BorderLayout.CENTER);
this.validate();
}
catch (Exception e) {}
}
if (jb.getLabel().equals("Predict orientation")){ // Predict Button
try {
runProcess(f);
}
catch (Exception e) {}
}
}
private void runProcess(File f)throws Exception {
this.f=f;
File workDir = new File("c:/msys/1.0/bin");
String[] cmdArray = new String[5];
String image = new String (f.getName());
cmdArray[0] = "c:/msys/1.0/bin/bash";
cmdArray[1] = "--login";
cmdArray[2] = "-i";
cmdArray[3] = "-c";
cmdArray[4] = "Extractor.sh " + image;
Process p = Runtime.getRuntime().exec(cmdArray, null, workDir);
StreamPumper out = new StreamPumper(new InputStreamReader(p.getInputStream()));
StreamPumper err = new StreamPumper(new InputStreamReader(p.getErrorStream()));
out.start();
err.start();
p.waitFor(); //here is the problem
out.join();
err.join();
File workDir2 = new File("c:/tesi");
String predictor = new String ("c:/tesi/predictor");
Process predict = Runtime.getRuntime().exec(predictor, null, workDir2);
StreamPumper out2 = new StreamPumper(new InputStreamReader(p.getInputStream()));
StreamPumper err2 = new StreamPumper(new InputStreamReader(p.getErrorStream()));
out2.start();
err2.start();
predict.waitFor();
out2.join();
err2.join();
}
class StreamPumper extends Thread {
InputStreamReader input;
StringBuffer buffer;
StreamPumper(InputStreamReader input) {
this.input = input;
buffer = new StringBuffer();
setDaemon(true);
}
public void run() {
try {
int c;
while ((c = input.read()) != -1) {
char ch = (char)c;
buffer.append(ch);
if (ch == '\n') {
System.out.append(buffer.toString());
buffer = new StringBuffer();
}
}
}
catch (Exception e) {
e.printStackTrace();
}
}
}
public IOD() { // Frame
super("Image Orientation Detector");
JButton open = new JButton("Load image");
JButton predict = new JButton("Predict orientation");
this.getContentPane().setLayout(new BorderLayout());
this.getContentPane().add(open, BorderLayout.NORTH);
this.getContentPane().add(predict, BorderLayout.SOUTH);
open.addActionListener(this);
predict.addActionListener(this);
this.setSize(300, 300);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE );
public static void main (String[] args) throws InterruptedException, IOException{
IOD d = new IOD();
}
}