PDA

View Full Version : How To Send STDOutput To The Dialog Frame In Real Time



jeoppy
06-24-2004, 05:10 AM
Hi

I Am running a ksh script in the UNIX machine - Trying To Get it's STDoutput and Send the Output To The frame of the Dialog in the following code - but i couldn't manage - and i don't get the text as it should be on the GUI-interface Text Box
Any idea as how to set it ??


import java.awt.Component;
import java.awt.Frame;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Vector;

import com.installshield.wizard.WizardBeanEvent;
import com.installshield.wizard.WizardUI;
import com.installshield.wizard.awt.AWTWizardUI;
import com.installshield.wizard.swing.SwingWizardUI;
import com.installshield.wizardx.actions.ExecWizardAction;

public class EnPreAct extends ExecWizardAction
{
Process prs;
BufferedReader stdInput;
String ls;
String lscom = new String("/opt/oob_dir/script/check.ksh");
String lsarg = new String(" proj=oob ver=1 -status");
WizardUI wizui;

wizui = event.getUserInterface();
//getting the user interface object ;
try
{
//This is where i try to get the STDout put of a process
prs = Runtime.getRuntime().exec(lscom + lsarg);
}
catch ( Exception e )
{
}

if ( prs != null )
{
stdInput = new BufferedReader(new InputStreamReader(prs.getInputStream()));
//And putting it into Buffered Stream So i can read it
}

while ( !procDone(prs) )
{
try
{
ls = stdInput.readLine();
}
catch ( Exception e )
{
}
while ( ls !=null )
{
//here I actually try to get the input into the Frame - so i will see all the STDout put in the Frame
showToUser(ls);
ls = null;
}
}
}

private boolean procDone(Process p) {
try
{
int v = prs.exitValue();
return true;
}
catch ( IllegalThreadStateException e )
{
return false;
}
}
//
private void showToUser(String arg0){

if ( wizui instanceof AWTWizardUI )
{
Frame frame = ((AWTWizardUI)wizui).getFrame( );
Frame cfr = (Frame)((SwingWizardUI)wizui).getCustomFrame();
Integer it = new Integer(cfr.getComponentCount());
Component pl[] = cfr.getComponents();
String comp = new String();
int i = 0;

//Here i managed to set the frame Title
cfr.setTitle(arg0);

//but here i am missing the part where the text should be added to the Text box - and i m not sure how to add it .
somehow the cfr should have the text box in it ....but alas - i don't manage it correctly or something ....


}
}
}

Thanks
Jeoppy

jeoppy
06-29-2004, 06:35 AM
ok - found it
you actually add the code to the DIALOG code
and not as an action
:


package com.installshield.enabler.event.dialog.swing;


import java.io.*;
import java.net.*;
import com.installshield.event.*;
import com.installshield.event.ui.*;
import com.installshield.event.wizard.*;
import com.installshield.event.product.*;
import com.installshield.wizard.*;
import com.installshield.wizard.service.*;
import com.installshield.wizard.awt.*;
import com.installshield.wizard.swing.*;
import com.installshield.wizard.console.*;
import com.installshield.product.*;
import com.installshield.util.*;
import com.installshield.ui.controls.*;
import com.installshield.database.designtime.*;

public class PanelPreTest2 //a dialog was greated named : "PreTest2"
//this dialog has a button and IS Frame (a text place)
{
public void initializeUIPreTest2(com.installshield.event.ui.ISDialogContext arg0)
{
arg0.getISPanel().getISHtmlControl("htm_text_box").setText("fff");
}
public void buttonClickedISButtonDef5(com.installshield.event.ui.ISControlContext arg0)
{
Process prs = null;
String Unix_Command=new String("find . -type f");
BufferedReader stdInput = null;
try {
//here the comand executes
prs = Runtime.getRuntime().exec(Unix_Command);
}
catch(Exception e){}

if(prs != null)
{
//initialization of a BufferReader to catch the STDOut of the process
stdInput = new BufferedReader(new InputStreamReader(prs.getInputStream()));
}
int v = 1;
String ls = new String("");
while(v!=100)
{
// LOOP Number II
try{
ls = stdInput.readLine();
}
catch(Exception e){}
while(ls !=null)
{
// LOOP Number I
//inserting line after line the STDOut to the text box
arg0.getISContainer().getISHtmlControl("htm_text_box").setText(ls);
ls = null;
}
v = prs.exitValue();
}
}
}