I am trying to make it so that when a user clicks a button, a new screen appears and automatically runs a command line process, and they are able to see the outputs of this process.
I thought that I might be able to use a JTextArea
to set text to.
Here's what I've got at the moment:
runButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent r)
{
JFrame runFrame = new JFrame("Running process...");
runFrame.setVisible(true);
runFrame.setSize(500, 400);
runFrame.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
runFrame.setLayout(null);
JTextArea run = new JTextArea();
run.setBounds(100,50,300,200);
runFrame.add(run);
Runtime runtime = Runtime.getRuntime();
Process process = null;
try
{
process = runtime.exec("cat /cmd/h:/testfile");
}
catch (IOException e)
{
e.printStackTrace();
}
InputStream runStream = process.getInputStream();
InputStreamReader runStreamReader = new InputStreamReader(runStream);
BufferedReader br = new BufferedReader(runStreamReader);
String line;
StringBuilder sb = new StringBuilder();
try
{
while ((line = br.readLine()) != null)
{
sb.append(line);
}
}
catch (IOException e)
{
e.printStackTrace();
}
run.setText(sb.toString());
}
});
The error I'm getting with this is:
Cannot run program "cat": CreateProcess error=2, The system cannot find the file specified
I was trying to test opening a file to test this, which just contains lines of random letters.
EDIT:
I'm not sure I explained clearly what I need this to do. What I want is for a command to be run in command line that opens a file. I then want the result of the command line to be output into the JTextArea.
EDIT 2:
I have tried to change my command to "ping riot.de -t". This will ping riots server every so often and it returns a response with the response time.
Upon running this, the new frame is just black, and java freezes up.