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);
 		catch (IOException e) {
	public void paint(Graphics g){

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

<applet code="execute.class",height="200" width="200">

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.

This article has been dead for over six months. Start a new discussion instead.