How to use Runtime.getRuntime().exec() in JSP? is it works in JSP or not

Hi to all,
i want run a .exe file from JSP file. In java i am able do this, using Runtime.getRuntime().exec().
but same thing, when i trying with JSP it is not working?
plz let me is there any other ways to do it..

It depends, usually (ie in an J2EE container) you're not allowed to access files or the runtime environment, by definition. What do you wan't to achieve with the exe?
--olaf                                                                                                                                                                                                                                                                                                                                                           

Similar Messages

  • Using Runtime.getRuntime().exec(DOS Program) with Windows 2000.

    I am trying to spawn a DOS Program from within Java.
    On Win95/98/ME, I use
    Process     p = Runtime.getRuntime().exec("START /w command.com con /c myDOSProgram.exe");
    This works on these platforms. On Win 2000, I use
    Process     p = Runtime.getRuntime().exec("START /w cmd.exe con /c myDOSProgram.exe");
    It does not work at all.
    I have tried all combinations of using START, cmd.exe, con /c, etc.
    I can spawn a Windows App using
    Process     p = Runtime.getRuntime().exec("windows.exe");
    And it works fine.
    What does it take to spawn a DOS program from Java on the Windows 2000 op sys?

    Hi. I recently wrote a java GUI that calls a DOS program with mixed success. Here's the code I used to make the call:String osName = System.getProperty("os.name" );
    String[] cmd = new String[4];
    if( osName.equals( "Windows 2000" ) || osName.equals( "Windows NT" ) )
         cmd[0] = "cmd.exe";
         cmd[1] = "/C" ;
         cmd[2] = "VBDoc.exe";
         cmd[3] = fileName;
    else if( osName.equals( "Windows 95" ) || osName.equals( "Windows 98" ) )
         cmd[0] = "command.com" ;
         cmd[1] = "/C" ;
         cmd[2] = "VBDoc.exe";
         cmd[3] = fileName;
    else
         System.out.println(osName);
    Process proc = runtime.exec(cmd);Check out this article, it gives a good explanation of how to use the exec() call:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
    Hope this helps!

  • Is there any way to run without using Runtime.getRuntime().exec()

    I am looking for a way to get my program to fun files on my system without using
    Runtime.getRuntime().exec() because it's causing me nothing but problems, is there any other way to do it without using this command?

    Can't think of an easier way (JNI, etc.).
    If you have not read the following article you really should, it might clear up a lot of your problems with exec():
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

  • How to execute an application in Solaris using Runtime.getRuntime.exec() ?

    I am currently doing a project which requires the execution of Solaris applications through the use of Java Servlet with this Runtime method - Runtime.getRuntime.exec()
    This means that if the client PC tries to access the servlet in the server PC, an application is supposed to be executed and launched on the server PC itself. Actually, the servlet part is not an issue as the main problem is the executing of applications in different platforms which is a big headache.
    When I tried running this program on a Windows 2000 machine, it works perfectly fine. However, when I tried it on a Solaris machine, nothing happens. And I mean nothing... no errors, no nothing. I really don't know what's wrong.
    Here's the code.
    public void doPost(HttpServletRequest request, HttpServletResponse response)
         throws ServletException, IOException
         response.setContentType("text/html");
         PrintWriter out = response.getWriter();
              Process process;                                                       Runtime runtime = Runtime.getRuntime();
              String com= "sh /opt/home/acrobat/";
              String program = request.getParameter("program");
              try
                        process = runtime.exec(com);
              catch (Exception e)
                   out.println(e);
    It works under Windows when com = "c:\winnt\system32\notepad.exe"
    When under Solaris, I have tried everything possible. For example, the launching of the application acrobat.
    com = "/opt/home/acrobat"
    com = "sh /opt/home/acrobat"I have also tried reading in the process and then printing it out. It doesn't work either. It only works when excuting commands like 'ls'
    BufferedReader read = new BufferedReader(new InputStreamReader(process.getInputStream()));Why is it such a breeze to execute prgrams under Windows while there are so many problems under Solaris.
    Can some experts please please PLEASE point out the errors and give me some advice and help to make this program work under Solaris! Please... I really need to do this!!
    My email address - [email protected]
    I appreciate it.
    By the way, I'm coding and compiling in a Windows 2000 machine before ftp'ing the .class file to the Solaris server machine to run.

    it is possible that you are trying to run a program that is going to display a window on an X server, but you have not specified a display. You specifiy a display by setting the DISPLAY environment variable eg.
    setenv DISPLAY 10.0.0.1:0
    To check that runtime.exec is working you should try to run a program that does not reqire access to an X Server. Try something like
    cmd = "sh -c 'ls -l > ~/testlist.lst'";
    alternatively try this
    cmd = "sh -c 'export DISPLAY=127.0.0.1:0;xterm '"
    you will also need to permit access to the X server using the xhost + command

  • Running curl command from a java program using Runtime.getRuntime.exec

    for some reason my curl command does not run when I run it from within my java program and errors out with "https protocol not supported". This same curl command however runs fine from any directory on my red hat linux system.
    To debug the problem, I printed my curl command from the java program before calling Runtime.getRuntime.exec command and then used this o/p to run from the command line and it runs fine.
    I am not using libcurl or anything else, I am running a simple curl command as a command line utility from inside a Java program.
    Any ideas on why this might be happening?

    thanks a lot for your response. The reason why I am using curl is because I need to use certificates and keys to gain access to the internal server. So I use curl "<url> --cert <path to the certificate>" --key "<path to the key>". If you don't mid could you please tell me which version of curl you are using.
    I am using 7.15 in my system.
    Below is the code which errors out.
    public int execCurlCmd(String command)
              String s = null;
              try {
                  // run the Unix "ps -ef" command
                     Process p = Runtime.getRuntime().exec(command);
                     BufferedReader stdInput = new BufferedReader(new
                          InputStreamReader(p.getInputStream()));
                     BufferedReader stdError = new BufferedReader(new
                          InputStreamReader(p.getErrorStream()));
                     // read the output from the command
                     System.out.println("Here is the standard output of the command:\n");
                     while ((s = stdInput.readLine()) != null) {
                         System.out.println(s);
                     // read any errors from the attempted command
                     System.out.println("Here is the standard error of the command (if any):\n");
                     while ((s = stdError.readLine()) != null) {
                         System.out.println(s);
                     return(0);
                 catch (IOException e) {
                     System.out.println("exception happened - here's what I know: ");
                     e.printStackTrace();
                     return(-1);
         }

  • Opening a new browser using Runtime.getRuntime().exec(cmd); under windows

    Can Runtime.getRuntime().exec(cmd); open a URL in to a new browser in wondows OS or ...can we force it to any specific browser insted on OS's default browser...
    It does open a new bowser under MAC but not under windows..
    cmd = "'rundll32 url.dll,FileProtocolHandler"+URL (windows)
    Thanks

    public class WindowsProcess
         public static void main(String[] args)
              throws Exception
              String[] cmd = new String[3];
              cmd[0] = "cmd.exe";
              cmd[1] = "/C";
              cmd[2] = "start";
              Process process = Runtime.getRuntime().exec( cmd );
              process = Runtime.getRuntime().exec( cmd );
    }When you run the above code you should get two open dos windows.
    Now just just enter some html filename and hit enter in each window. IE should start up separately in each window.
    Thats also what should happen if you specify the html file as the fourth parameter. A new process should be created and two separate windows should open with a browser in each.

  • Runtime.getRuntime().exec() in JSP - Starting a batch

    Hi,
    I am trying to start a batch from a jsp in the following way:
    try{
    String path = "bat/drucken";
    ProcessBuilder processBuilder = new ProcessBuilder(path);
    Process process = processBuilder.start();
    out.println("<script type=\"text/javascript\">alert('ausgeführt.');</script>");
    }catch(Throwable t){
    t.printStackTrace();
    out.println("<script type=\"text/javascript\"> alert('Fehler beim Drucken.');</script>");
    But onfortunately it does not work the way I want.
    If I double click the batch file, it works properly and starts a visual basic script, that makes out of n word-documents one single one.
    If I start it like above, then nothing happens and just the alert('ausgeführt') appears.
    How can I start a VB script or a commands of the shell from inside a jsp ?
    PS: using Windows XP, jsp should work on a Windows Server

    As Liane said, this should NOT be in your JSP. This should be in a normal Java file, compiled to a class, in a package, and deployed in the Web Application's /WEB-INF/classes/ directory.
    Example. Change the code to this:
    //Put your class in a package
    package debbie.in.florida;
    import java.io.*;
    public class Console{
        String error = null;
        String output = null;
        public String getError(){
            return error;
        public String getOutput(){
            return output;
        /** Called from inside the jsp like new Console().exec("cscript drucken.vbs param1 param2") **/
        public void exec(){
            try{
                String osName = System.getProperty("os.name" );
                String[] cmd = new String[3];
                cmd[0] = "cmd.exe" ;
                cmd[1] = "/C" ;
                cmd[2] = "Test.exe";
                Runtime rt = Runtime.getRuntime();
                System.out.println("Execing " + cmd[0] + " " + cmd[1] + " " + cmd[2]);
                Process proc = rt.exec(cmd);
                // any error message?
                grabStream(proc.getErrorStream(), "error");
                // any output?
                grabStream(proc.getInputStream(), "output");
                // any error???
                int exitVal = proc.waitFor();
                if (exitVal != 0)
                    error += "ExitValue: "+exitVal;
            } catch (Exception e){
                e.printStackTrace();
        private void grabStream(InputStream is, String msg){
            if (!(msg.equals("error") || msg.equals("output")))
                return;
            String message = "";
            try{
                InputStreamReader isr = new InputStreamReader(is);
                BufferedReader br = new BufferedReader(isr);
                String line=null;
                while ( (line = br.readLine()) != null)
                    message += line;
            } catch (IOException ioe){
                ioe.printStackTrace();
            if (msg.equals("error"))
                error = message;
            else
                output = message;
    }Then compile the code and move the Console.class file to <web application>/WEB-INF/class/debbie/in/florida/Console.class. The folder should be debbie/in/florida because the package is defined as debbie.in.florida.
    Then your JSP would look like:
        <%//Use the debbie.in.florida namespace because your class is in a package
            debbie.in.florida.Console console = new debbie.in.florida.Console();
        %>
        <script type="text/javascript">
            alert("start");
        </script>
        <%
            console.exec();
            String error = console.getError();
            String output = console.getOutput();
        %>
        <script type="text/javascript">
            alert("end, output = <%=output%> and error = <%=error%>");
        </script>There is a lot wrong with this code, but I won't go and try to fix design problems here, That will be for a later day. But if things are working you should get two popups, one at the start, then your code should execute (or you should get an error message if something is wrong with the code), then a second popup at the end with the response from your application.

  • How to use Runtime.getRuntime("command") in win?

    I dont know how to use this method in win entironment, for example about file opertions, where there is some documents on detail about it?

    Huh?
    There is a method called Runtime.getRuntime(). It does not take any parameters. The javadocs describe it.
    Is that what you are asking about?

  • Runtime.getRuntime().exec() - native process

    Hi,
    I want to start a native (openFt) program from within my servlet. Therefore, I use Runtime.getRuntime().exec(String [] cmd). This works fine in my local OC4J container: the process is terminated with error code 0 and the native program is executed. The only strange thing here is that the output text isn't in my InputStream but in my ErrorStream.
    The real problem arises when I deploy the same Ear on the 9ias server. Here, the process doesn't execute my native command, terminates with error code 128 and leaves no inputStream and no errorStream.
    Errorcode 128 means that there are no child processes to wait for. (i call process.waitFor() to obtain the error code). I think this means my process isn't even started.
    Anyone familiar with processes in OC4J & 9IAS?
    Thanx in advance

    I guess your implementation of matchIp() is wrong:
    public class ReaderTest {
        public static void main(String[] args) {
            new ReaderTest().testReaderMethod();
        private void testReaderMethod() {
            ByteArrayInputStream dummyStrem = new ByteArrayInputStream(
                    ("*******************************************\n"
                            + "*   My shell Application                   *\n"
                            + "\n"
                            + "*******************************************\n"
                            + "\n" + " \n" + "\n" + "HELP: h\n" + "\n"
                            + "COMMAND: c\n" + "\n" + "QUIT:q\n" + "\n"
                            + "135.19.45.18> ").getBytes());
            System.out.println(readUntilIpMatch(dummyStrem));
        private StringBuilder buffer = new StringBuilder();
        protected String readUntilIpMatch(final InputStream in) {
            while (true) {
                try {
                    if (in.available() > 0) {
                        buffer.append((char) in.read());
                        Pattern pattern = Pattern
                                .compile("\\d{1,3}(\\.\\d{1,3}){3}(?=\\D)");
                        Matcher matcher = pattern.matcher(buffer);
                        if (matcher.find()) {
                            return matcher.group();
                } catch (final IOException e) {
                    throw new RuntimeException(
                            "Failed to read buffer in while looking for prompt!", e);
        } // runs forever if not matching!!!!
    bye
    TPD

  • How would you capture the stdout of Runtime.getRuntime().exec())?

    How would you capture the stdout of Runtime.getRuntime().exec())?
    Say you wanted to execute PKZIP25.exe from java using Runtime.getRuntime().exec(). How would you capture the output of PKZIP25 (the console IO) in a file so you could check the results?
    Thanks
    Bill Blalock

    Thanks.
    Could you explain a little more?
    The program I am calling seems to be executing, as far as Java is concerned, but nothing happens. I imagine I have made mistakes in calling it but can't see the output to the console.
    Should I use Runtime.getRuntime().exec() or Runtime.exec() for something like this?
    I appreciate the help!
    Bill B.

  • Using Process Runtime.getRuntime().exec

    http://im1.shutterfly.com/procserv/47b4d633b3127cceb46774c84ee80000001610
    Here is a URL to a part of the current process I need to run. Actually there are 4 steps that preceed these but they are ran in order and must be done before these (that part is easy). Sorry it kinda chopped off the left side a little bit.
    My question is, can I do this entirely using Runtime.getRuntime().exec() commands or do I need to involve multi threading. The reason I am asking is because P13 cannot run until P8 and P9 completes, but that shouldn't stop the rest of the program from running.
    If I have something like
    Process P4 = Runtime.getRuntime().exec(P4);
    Process P5 = Runtime.getRuntime().exec(P2);
    // Some handling for the streams of these processes goes here
    P4.waitFor();
    P2.waitFor();
    if(P2.exitValue() != 0){
    Process P5 = Runtime.getRuntime().exec(P5);
    Process P6 = Runtime.getRuntime().exec(P6);
    // Some handling for the streams of these processes goes here
    Does that mean the whole program will stop and wait until P4 is done before even checking for P2? If P2 is finished would the program continue and run P5 and P6 even if P4 is still running or will it wait for P4 to complete also. P4 has nothing to do with P2?
    Also any advice ???

    P4 and P2 will both be running in parallel (or as much as your OS and hardware allows them to be). As soon as both are done, and regardless of which finishes first, whatever follows P2.waitFor() will execute.
    If you have multiple groups of processes, where the processes within a group must execute sequentially, but the groups themselves can run independently of each other, then you'll need to either use Java's threads, or wrap each group of sequential processes in a shell script or batch file the executes that group sequentially.
    If there are complex dependencies among the groups--that is, multiple groups must wait on the same process, or one group must wait for multiple other groups, then it might be easier to control the concurrency in Java.

  • Access denied when Runtime.getRuntime().exec

    I have an applet that opens a JFrame.
    In the JFrame I have a JButton, when I click the button I want a browser to open with a specific website.
    This doesn't work.
    When I look in the cmd-prompt it says:
    "java.security.AccessControlException: access denied (java.io.FilePermission C:\Program execute)"
    What have I done wrong? Do I have to change the security settings? Where do I that?
    class KnappListener implements ActionListener {
    public void actionPerformed(ActionEvent e) {
    frame2 = new JFrame(e.getActionCommand());
    frame2.addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {System.exit(0);}});
    String website = new String("http://www.microsoft.com");
    try {
    Runtime.getRuntime().exec("C:\\Program Files\\Internet Explorer\\IEXPLORE.exe"+website);
    //Runtime.getRuntime().exec("cmd/C"+"start.exe"+website);
    catch (IOException io) {}
    }

    it doesn't matter which class your program extends. if your program is an applet (running in a browser) it is not permitted to use Runtime.getRuntime().exec(). If your program is an application, it is allowed to do so.
    I think there is a way for applets to get the permission through a policy, but I don't know how to do this.

  • Runtime.getRuntime().exec(java method); - Passing strings between methods

    Hi all,
    I am using Runtime.getRuntime().exec(java xxxxxx); to run a java program from within a java program, i also need to pass a string to the new program. Does anyone know how to do this?
    Matt

    how would i retrive those strings in myApp as i want
    to put the values from them in a JLabelYou have a main method like this, right?
    public static void main(String[] args) { ... }
    args contains the array of strings passed to the app from the command line.

  • Runtime.getRuntime().exec("cmd /c start file\\"+"My file.txt" ) Not work

    Hello
    i have a problem I use:
    Runtime.getRuntime().exec("cmd /c start file\\"+"My file.txt");
    to open "my file.txt" And I have error System Windows don't open file file\My becaus file My don't exist When I rename file to "Myfile.txt" and use:
    Runtime.getRuntime().exec("cmd /c start file\\"+"Myfile.txt");
    It's work great. My problem is when my file have space in name or other [ ], etc symbol. How fix this problem?
    Thenks to help:)

    Try using the verson where you specify the parameters in an array as this example shows:
    http://forum.java.sun.com/thread.jspa?forumID=31&threadID=635363
    Note: you may need to enclose the file name in quotes

  • Runtime.getRuntime().exec works on windows failed on linux!

    Hi,
    I'm trying to execute a linux command from java 1.4.2 using Runtime.getRuntime().exec(). The linux command produces output and write to a file in my home dir. The command runs interactively in the shell and also run on windows.
    The command is actually a mozilla pk12util. My java code to run this pk12util works on windows, but not on linux (fedora). When I print out the command I'm trying to run in java, I can run it interactively in bash shell.
    Method below is where the problem seems to be:
    public void writeCert() {
    // Declaring variables
    System.out.println("Entering writeCert method");
    String command = null;
    certFile = new File(credFileName);
    // building the command for either Linux or Windows
    if (System.getProperty("os.name").equals("Linux")) {
    command = linuxPathPrefix + File.separator + "pk12util -o "
    + credFileName + " -n \"" + nickName + "\" -d "
    + dbDirectory + " -K " + slotpw + " -w " + slotpw + " -W "
    + pk12pw;
    System.out.println("System type is linux.");
    System.out.println("Command is: " + command);
    if (System.getProperty("os.name").indexOf("Windows") != -1) {
    // command = pk12utilLoc + File.separator + "pk12util -o
    // "+credFileName+" -n "\"+nickname+\"" -d \""+dbDirectory+"\" -K
    // "+pk12pw+" -w "+pk12pw+" -W "+pk12pw;
    command = pk12utilLoc + File.separator + "pk12util.exe -o "
    + credFileName + " -n \"" + nickName + "\" -d "
    + dbDirectory + " -K " + slotpw + " -w " + slotpw + " -W "
    + pk12pw;
    System.out.println("System type is windows.");
    System.out.println("Command is: " + command);
    // If the system is neither Linux or Windows, throw exception
    if (command == null) {
    System.out.println("command equals null");
    try {
    throw new Exception("Can't identify OS");
    } catch (Exception e) {
    System.out.println(e.getMessage());
    e.printStackTrace();
    // Having built the command, running it with Runtime.exec
    File f = new File(credFileName);
    // setting up process, getting readers and writers
    Process extraction = null;
    BufferedOutputStream writeCred = null;
    // executing command - note -o option does not create output
    // file, or write anything to it, for Linux
    try {
    extraction = Runtime.getRuntime().exec(command);
    } catch (IOException e) {
    System.out.println(e.getMessage());
    e.printStackTrace();
    // Dealing with the the output of the command; think -o
    // option in command should just write the credential but dealing with output anyway
    BufferedWriter CredentialOut = null;
    OutputStream line;
    try {
    CredentialOut = new BufferedWriter (
    new OutputStreamWriter(
    new FileOutputStream(credFileName)));
    catch (FileNotFoundException e) {
    System.out.println(e.getMessage());
    e.printStackTrace();
    // writing out the output; currently having problems because I am trying to run
    }

    My error is due to the nickname "-n <nickname" parameter error. I think the problem is having a double quotes around my nickname, but if I take out the double quotes around my nickname "Jana Test's ID" won't work either because there are spaces between the String. Error below:
    Command is: /usr/bin/pk12util -o jtest.p12 -n "Jana Test's Development ID" -d /home/jnguyen/.mozilla/firefox/zdpsq44v.default -K test123 -w test123 -W test123
    Read from standard outputStreamjava.io.PrintStream@19821f
    Read from error stream: "pk12util: find user certs from nickname failed: security library: bad database."
    null
    java.lang.NullPointerException
    at ExtractCert.writeCert(ExtractCert.java:260)
    at ExtractCert.main(ExtractCert.java:302)
    Code is:
    private String nickName = null;
    private void setNickname(String nicknameIn) {
    nickName = nicknameIn;
    // building the command for either Linux or Windows
    if (System.getProperty("os.name").equals("Linux")) {
    command = linuxPathPrefix + File.separator + "pk12util -o " + credFileName + " -n \"" + nickName + "\" -d " + dbDirectory + " -K " + slotpw + " -w " + slotpw + " -W " + pk12pw;
    System.out.println("System type is linux.");
    System.out.println("Command is: " + command);
    extraction = Runtime.getRuntime().exec(command);
    BufferedReader br = new BufferedReader(
    new
    InputStreamReader(extraction.getErrorStream()));
    PrintStream p = new PrintStream(extraction.getOutputStream());
    System.out.println("Read from standard outputStream" + p);

Maybe you are looking for

  • ESYU: MMT,MMTT,MTI (Sales Orders/Internal Orders)에 중복된 record 확인

    Purpose Oracle Inventory Management - Version: 11.5.4 to 11.5.10 Information in this document applies to any platform. 이 문서는 여러 errors 때문에 pending transactions(MMTT)이나 open interface(MTI)에 존재하는 중복된 records를 찾는데 도움을 줄 것이다. Error를 분석하기 전에 어떤 duplicates

  • Cannot print wirelessly from MacBook Pro OSX Mavericks

    I cannot get my new MacBook Pro (using OSX Mavericks) to communicate with my HP Officejet4500 Wireless.  I can print when I use a connecting USB cable, but cannot print wirelessly.  All of my Mac software updates are current as of 4/20/2014, which in

  • Error Handling - displaying Error on ALL error events

    I am trying to set up a global error handling page error.cfm so that whenever any error at all occurs I can display my error.cfm page. At first I tried the following in the application.cfm page, and then ran a page that tried to output a variable tha

  • [Help] How you guys do the performance test for Hyperion?

    Dear All, Currently, we are building the performance test scripts by using the QALoad. We have identified the following areas for the test. * Planning Data Form * Financial Report * SmartView However, we hit a number of question. For Financial Report

  • T61 and port replicator with 2 monitors

    I have a T61, 6460-66U, connected to a port replicator. My laptop stays closed and out of sight. I have a Y connector going from the analog video port to each of the LCD monitors. The displays work, but they are clones of each other. I want one to be