1,105,585 Community Members

Executing a terminal command with an applet

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

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.

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