-2

In a standard java program I am able to do the following:

import java.io.*;
public class PingApp
{
    public static void main(String args[])
    {
        System.out.println("about to try to launch ping...");
        try
        {
            Process p = Runtime.getRuntime().exec("ping -o google.com"); 
            p.waitFor(); 
            BufferedReader reader=new BufferedReader(
                new InputStreamReader(p.getInputStream())
            );
            String line=reader.readLine(); 
            while(line!=null) 
            { 
                System.out.println(line);
                line=reader.readLine(); 
            }
        }
        catch(IOException e1) {
            System.err.println(e1.getMessage());
        } 
        catch(InterruptedException e2) {
            System.err.println(e2.getMessage());
        } 
        System.out.println("finished.");
    }
}

I would like to do exactly the same thing in a java applet, except instead of printing the output I capture to the terminal, I would like to display it in the applet's window in the browser.

That's it.

The error I am running into when I try to put this code into an applet is:

Exception in thread "AWT-EventQueue-3" java.security.AccessControlException: access denied ("java.io.FilePermission" "<<ALL FILES>>" "execute")

Is there any way I can get around this AccessControlException?

Thanks.

tadasajon
  • 14,276
  • 29
  • 92
  • 144
  • Yes; ask the user if they'll allow you to do that on their computer. More than likely, however, the answer is going to be "no". – Brian Roach Aug 08 '13 at 20:02
  • Are you attempting to ping as a test for connectivity before attempting some other action? If so, why not just attempt the action and catch/handle any exceptions that occur. Also, there are many cases where a ping will succeed and the following action will fail (following action not allowed by firewall or server, some change in network or server in between ping and following action, etc...), so you will need to catch/handle exceptions regardless of the ping result. – R Dub Aug 08 '13 at 20:12

2 Answers2

2

That's a security feature of Java to stop you from maliciously using a user's Terminal or equivalent, and from reading or writing to the drive.

The only way around this is to SIGN the applet.

1

your applet should be signed first. check this out:

Java applet: run native code from browser?

Then use Runtime.exec to start it.

Community
  • 1
  • 1
MasterPlanMan
  • 992
  • 7
  • 14