1,105,214 Community Members

Executing a terminal command with an applet

Member Avatar
JPramod
Newbie Poster
3 posts since Jun 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi,
I am running Ubuntu in my machine and I tried this code:

import java.io.InputStream;
import java.io.IOException;
import java.applet.Applet;
import java.awt.*;

public class execute extends Applet{
	String output="";
	public void init(){	
		try {
    				// Execute command
    				String command = "ls";
   				Process child = Runtime.getRuntime().exec(command);

    				// Get the input stream and read from it	
    				InputStream in = child.getInputStream();
    				int c= in.read();
        			while ((c = in.read()) != -1) {
        			output =output+((char)c);
    				}
    				in.close();
			}			
 		catch (IOException e) {
		}
		
		System.out.println(output);
	}
	public void paint(Graphics g){
		g.drawString(output,60,100);
	}
}

And then wrote this html file and saved it in the same directory:

<html>
<head><title>Applet</title>
<body>
<applet code="execute.class",height="200" width="200">
</body>
</html>

What I'm trying to do here is to run the ls shell command in an applet and display the results.

The code compiles with no errors. But when I open the html file in the browser, I just get a gray square.

Is this because of security issues that I don't get anything? Or is it because of an error in the code? Or is it the browser that is the problem?

Please help,
Thanks in advance.

Member Avatar
mKorbel
Nearly a Posting Virtuoso
1,345 posts since Feb 2011
Reputation Points: 274 [?]
Q&As Helped to Solve: 277 [?]
Skill Endorsements: 14 [?]
 
0
 
You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: