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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.