Hi Abhay and Panton, As Abhay suggested, I tried to execute the servlet from other PC, but the same Exception error occurs... //////////////////// Error Execute java.security.AccessControlException: access denied (java.io.FilePermission C:\winnt\system32\cmd.exe execute) /////////////////// For your information, my OS is NT Server 4.0, and I am using J2SE build 1.3. 0 and J2EE ver. 1.2.1 as Servlet container... The code is as follows: /////////////// import java.io.*; import javax.servlet.*; public class HelloWorldServlet extends GenericServlet { public void service ( ServletRequest req, ServletResponse res ) throws ServletException, IOException { String command = "C:\\winnt\\system32\\cmd.exe"; res.setContentType("text/html"); PrintWriter pw = res.getWriter(); pw.println("<HTML><HEAD><TITLE>"); pw.println("HelloWorld"); pw.println("</TITLE></HEAD><BODY>"); pw.println("<CENTER><H1>Hello World!</H1></CENTER>"); pw.println("</BODY></HTML>"); Runtime r = Runtime.getRuntime(); Process p = null; try { p = r.exec(command); pw.println("<CENTER><H1>You made it!</H1></CENTER>"); } catch (Exception e) { System.out.println("Error Execute " + e); pw.println("<CENTER><H1>EXEC failed!</H1></CENTER>"); } pw.flush(); pw.close(); } } ////////////////////////// Thanks for sparing your time... rgs, Hiroshi -----Original Message----- From: Abhay [mailto:[EMAIL PROTECTED]] Sent: Saturday, November 18, 2000 12:27 PM To: [EMAIL PROTECTED] Subject: Re: How to invoke system call using Servlet? Hi Hiroshi, There can be problem if u are trying to execute the command on the same PC. i.e. the same PC acting as client as well as server. According to my knowledge , as long as u are accessing the executables on the server generating the servlet, there should be no problem. Actually, I am using such a servlet calling a batch file on NT machine. In this case, u meight be trying to access the server ( i.e. u'r PC ) but the same is again acting as client. This meight throw security exception. Try using different PC as a client. Abhay ----- Original Message ----- From: Syukur, Hiroshi Ridwan <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Friday, November 17, 2000 3:30 PM Subject: Re: How to invoke system call using Servlet? > Thanks Abhay, > > I could execute the same executable if I use the console java program, but I > got the following exception when I try it via Servlet: > > Error Executingjava.security.AccessControlException: access denied (java.io. > FilePermission ExecutableProgram.exe execute) > > I found the same question was asked in www.jGuru.com, but still no answer > available..( http://www.jguru.com/jguru/faq/orphan_view.jsp?EID=76909 ) > "How do I use the security manager to grant persissions for the servlet to > call the exec() method of java.lang.Runtime to run a native app on the > server?" > > regards, > Hiroshi > > > > -----Original Message----- > From: Abhay [mailto:[EMAIL PROTECTED]] > Sent: Friday, November 17, 2000 5:32 PM > To: [EMAIL PROTECTED] > Subject: Re: How to invoke system call using Servlet? > > > Hi Syukur, > What u have done is perfectly all right. U should just see that the > Executable Program should be command line executable on the system like some > batch file on WINDOWS Platform. Your program should work finr. What > exception is it throwing ? > > Abhay > > ----- Original Message ----- > From: Syukur, Hiroshi Ridwan <[EMAIL PROTECTED]> > To: <[EMAIL PROTECTED]> > Sent: Friday, November 17, 2000 11:22 AM > Subject: How to invoke system call using Servlet? > > > > Hello All, > > > > Is there any way I can execute Runtime.exec() method from Servlet? > > > > I tried to insert the following code inside the doPost() method of my > > servlet, both directly or using another class but I keep getting the > > Exception error. > > > > //////// > > Runtime r = Runtime.getRuntime(); > > Process p = null; > > try { > > p = r.exec(ExecutablesProgram); > > } catch (Exception e) { > > System.out.println("Error Executing"); > > } > > /////// > > Then, when I try to insert the code outside the doPost() method, the code > > was not executed at all... > > > > I am a novice in Servlet (and Java...), so I don't now whether Servlet is > > allowed to invoked a system call or not. If not, how can I invoke a system > > call from Web browser? (Like Perl CGI's system() function ) > > > > Thanks in advance. > > > > Regards, > > Hiroshi > > > > > > > > > > > > > > Runtime.getRuntime().exec(unix_command); > > > > > ___________________________________________________________________________ > > To unsubscribe, send email to [EMAIL PROTECTED] and include in the > body > > of the message "signoff SERVLET-INTEREST". > > > > Archives: http://archives.java.sun.com/archives/servlet-interest.html > > Resources: http://java.sun.com/products/servlet/external-resources.html > > LISTSERV Help: http://www.lsoft.com/manuals/user/user.html > > > > ___________________________________________________________________________ > To unsubscribe, send email to [EMAIL PROTECTED] and include in the body > of the message "signoff SERVLET-INTEREST". > > Archives: http://archives.java.sun.com/archives/servlet-interest.html > Resources: http://java.sun.com/products/servlet/external-resources.html > LISTSERV Help: http://www.lsoft.com/manuals/user/user.html > > ___________________________________________________________________________ > To unsubscribe, send email to [EMAIL PROTECTED] and include in the body > of the message "signoff SERVLET-INTEREST". > > Archives: http://archives.java.sun.com/archives/servlet-interest.html > Resources: http://java.sun.com/products/servlet/external-resources.html > LISTSERV Help: http://www.lsoft.com/manuals/user/user.html > ___________________________________________________________________________ To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff SERVLET-INTEREST". Archives: http://archives.java.sun.com/archives/servlet-interest.html Resources: http://java.sun.com/products/servlet/external-resources.html LISTSERV Help: http://www.lsoft.com/manuals/user/user.html ___________________________________________________________________________ To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff SERVLET-INTEREST". Archives: http://archives.java.sun.com/archives/servlet-interest.html Resources: http://java.sun.com/products/servlet/external-resources.html LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to