0

I have a Solaris script that I use to connect to SQLPlus. At the end of this script, I am given the SQL> prompt. The script looks like this:

`#!/bin/ksh
echo Setting ORACLE_HOME ..
export ORACLE_HOME=<path>
echo Setting ORACLE_SID ..
export ORACLE_SID=<SID>
echo Setting PATH ..
export PATH=$PATH:$ORACLE_HOME/bin
echo
echo Connecting to SQLPlus ..
$ORACLE_HOME/bin/sqlplus pdmlink80/pd1016I65@P38`

Now, I a trying to create a java swing UI with a button on it, clicking which will execute this script in the background and I should get the same SQL> prompt. The swing code looks like this:

public class ButtonExample extends JFrame {

  public ButtonExample() {
    initUI();
  }

  private void initUI() {

    JPanel panel = new JPanel();
    getContentPane().add(panel);

    panel.setLayout(null);

    JButton myButton = new JButton("Button");
    myButton.setBounds(50, 60, 80, 30);

    myButton.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent event) {
        String s;
        Process p;

        try {
          p = Runtime.getRuntime().exec("/usr1/ptc/Windchill_9.1/Windchill/bin/windchill shell");
          p.waitFor();
          BufferedReader br = new BufferedReader(
              new InputStreamReader(p.getInputStream()));

          while ((s = br.readLine()) != null){
            System.out.println(s);
            break;
          }
          System.out.println ("exit: " + p.exitValue());
          JOptionPane.showMessageDialog(null,"Script successfully executed!!");
        } 
        catch (Exception e) {}
      }
    });

    panel.add(myButton);

    setTitle("ButtonExample");
    setSize(300, 200);
    setLocationRelativeTo(null);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
  }


  public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {
      @Override
      public void run() {
        ButtonExample ex = new ButtonExample();
        ex.setVisible(true);
      }
    });
  }

But when I execute this code, I obviously do not get the SQL prompt. What can I do to get the prompt?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Mite5h
  • 1
  • 1
    Take a look at this; http://stackoverflow.com/a/3644288/1241311 and this; http://stackoverflow.com/a/1732506/1241311 – Iarwa1N Jul 05 '13 at 14:03
  • Note that `waitFor()` blocks the subsequent attempt to read `stdout` from `p`; also consider `ProcessBuilder`. – trashgod Jul 05 '13 at 18:09

0 Answers0