Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Runtime

 
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone,

I am using the Runtime class to run a java program by using the java intreperter.

This is what i am doing to get the output stream of the java program



Now this is the java program i am running



The thing is the java program runs and everything is alright but i am not getting its console output by the way i am doing it.

I am right in that to get the output of a program, i get its inputstream and not outputstream right?

I am also using threads to run the program but that should have no effect right?

If what i am doing is wrong could someone guide me on the right way to get the output stream of a program

Any help is greatly appreciated

Thank You

Yours Sincerely

Richard West
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
believe it or not I get the output!
 
Richard West
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone,

Jean, i am listing a Runs class and a sample swing program so you can compile them and see what i mean first hand.

i tried running the above JTest program of mine with the below Runs class and it works but now here comes the weird part, it does not work with a swing application as i will list.

You see the runtime in my program does not seem to be able to get any output streams from the swing program

This is what i am doing to run the swing application



now this is the simple swing program is running



Now the problem is that when i run the above swing program using my Runs class(listed above) and click on their JButtons the console is supposed to output the corresponding JButton that is clicked.

Now i am still not able to read the console output. I have a feeling that the problem has to do with the while loops in the Runs class i have above but i am not sure and i can't prove it.

Am i missing something or am i doing something wrongly?

I hope someone can guide me how to do this correctly

Any help is greatly appreciated

Thank You

Yours Sincerely

Richard West
 
Jean-Sebastien Abella
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i can assure that i get the output either from the first Test class or the second JButtons one..

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class test {
public static void main(String[] args) {


String str18 = "java JButtons";
String str20 = null;

Runtime Runtime1 = Runtime.getRuntime();

try {
Process Process1;
Process1 = Runtime1.exec(str18);


//This is the line where i am trying to get the output stream of the java
//program by getting its inputstream. I am right am i not or do i have
//to get its outputstream of the program instead

BufferedReader in = new BufferedReader(new InputStreamReader(Process1.getInputStream()));

while ((str20 = in.readLine()) != null)
{
System.out.println(str20);
}

Process1.waitFor();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

and
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

public class JButtons implements ActionListener

{

JFrame fr = new JFrame ("Frame");
JLabel Label1 = new JLabel("Label1 ",SwingConstants.RIGHT);
JButton Button1 = new JButton("Button 1");
JButton Button2 = new JButton("Button 2");

public void initialize ()
{
Container pane = fr.getContentPane();
pane.setLayout(new FlowLayout());
fr.setSize(250,300);
fr.setLocation(300,300);
fr.setBackground(Color.lightGray);
pane.add(Label1);

pane.add(Button1);
pane.add(Button2);

fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Button1.addActionListener(this);
Button2.addActionListener(this);
fr.pack();
fr.setVisible(true);
}

public void actionPerformed(ActionEvent event)
{
JComponent b = (JComponent)event.getSource();

if(b == Button1)
{
Label1.setText("Button 1 clicked");
System.out.println("You clicked Button 1");
}

else if(b == Button2)
{
Label1.setText("Button 2 clicked");
System.out.println("You clicked Button 2");
}

}
public static void main(String args[])
{
JButtons a = new JButtons();
a.initialize();
}
}


and i called at prompt java test
output is...

You clicked Button 2
You clicked Button 1
You clicked Button 2
 
Jean-Sebastien Abella
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
and if i commented the system.out in the first file the one that call Runs I don't have any output...
 
All that thinking. Doesn't it hurt? What do you think about this tiny ad?
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic