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

Similar Messages

  • 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                                                                                                                                                                                                                                                                                                                                                           

  • 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

  • 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!

  • 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.

  • 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.

  • How to recognize if application is installed using "Install Application on Remote Desktop" option on Windows Server 2008 R2

    How to recognize if application is installed using "Install application on remote desktop..." option in Control Panel in Windows Server 2008 R2?
    Basically, as administrator, I can't say if the user installed application using "Install application on remote desktop..." in Control Panel or he just installed it by clicking the .msi executable. I can't find anything that makes any difference.
    I could not find anything in the registry. I am quite confused.
    Thanks,
    Aleksandar9

    Hi,
    Thank you for your posting in Windows Server Forum.
    Please make sure that you are using category view of control panel-programs to check the application. And in addition to “install application on Remote Desktop server” user can also use command line also.
    change user /install
    change user /execute
    change user /query
    “The first time you run the application, it searches the home directory for its .ini files. If the .ini files are not found in the home directory, but are found in the system directory, Terminal Services copies the .ini files to the home directory, ensuring
    that each user has a unique copy of the application .ini files. Each user should have a unique copy of the .ini files for an application. This prevents instances where different users might have incompatible application configurations.” (Quoted formthis
    article).
    Hope it helps!
    Thanks,
    Dharmesh

  • How to execute windows application in Jinternal frame

    I want to execute windows application in a JInternal Frame ?

    Attach an EventListener and
    try{ Runtime.getRuntime().exec("C:\\Program Files\\Outlook Express\\ ..."); }
              catch(Exception e){}

  • Not able to execute external file with parameter using RuntIme

    When I try tio execute the following command :
              String command="C:\\Program Files\\BMC Software\\CONTROL-M EM 6.2.01\\bin\\deftable.exe -u abc -p abc567 -s q23.nz.dq.com -src DBIQ-EURILIBORROB.exp";
    Process p = Runtime.getRuntime().exec(command);
    It gives "File 'DBIQ-EURILIBORROB.exp' is Missing." even though the file is available in the given location. Please help
    Regards
    Edited by: Robin_Jacob on Aug 14, 2009 5:09 AM

    Thanks a lot mate.. It works now.. But i had to do a little more changes.
    I was getting an exception
    java.lang.IllegalThreadStateException: process has not exited
         at java.lang.ProcessImpl.exitValue(Native Method)
         at com.Test.test1(Test.java:94)
         at com.Test.main(Test.java:23)
    when my code was like this:
    File f = new File ("C:\\Program Files\\BMC Software\\CONTROL-M EM 6.2.01\\bin"); // The working directory - not the file to be processed
    String[] command = {f.getAbsolutePath() + "\\deftable.exe", "-u", "abc", "-p", "abc567", "-s", "q23.nz.dq.com", "-src","DBIQ-EURILIBORROB.exp"};
    Process proc = Runtime.getRuntime().exec(command,null,f);
    int exitVal = proc.exitValue();
    } catch (Throwable t){
    t.printStackTrace();
    But it worked when i changed the code as shown below it worked fine
    public static void test1() throws IOException
    File f = new File ("C:\\Program Files\\BMC Software\\CONTROL-M EM 6.2.01\\bin"); // The working directory - not the file to be processed
    String[] command = {f.getAbsolutePath() + "\\deftable.exe", "-u", "abc", "-p", "abc567", "-s", "q23.nz.dq.com", "-src","DBIQ-EURILIBORROB.exp"};
         Process proc = Runtime.getRuntime().exec(command,null,f);
         InputStream in = proc.getInputStream();
              InputStream err = proc.getErrorStream();
              BufferedReader readIn = new BufferedReader(new InputStreamReader(in));
              BufferedReader readErr = new BufferedReader(new InputStreamReader(err));
              int b;
              int exit = -1;
              boolean bReady = false;
              while (!bReady) {
                   try {
                        exit = proc.exitValue();
                        bReady = true;
                   } catch (IllegalThreadStateException isex) {
                   suckStreams(readIn, readErr);
              readIn.close();
              readErr.close();
              System.out.println("Exit Status :" + exit);
    public static void suckStreams(BufferedReader readIn, BufferedReader readErr) {
              try {
                   while (readIn.ready() || readErr.ready()) {
                        if (readIn.ready())
                             System.out.println(readIn.readLine());
                        if (readErr.ready())
                             System.err.println(readErr.readLine());
              } catch (IOException ex) {
                   System.err.println("suckStreams: " + ex);
         }

  • Swign application and Runtime.getRuntime().exec(cmd)

    i want to use this program in a swing application, when i press the button it will execute this comand,?? is possible?
    String[] cmd = {"pwd","ls"};
    try {
    Process ls = Runtime.getRuntime().exec(cmd);
    BufferedReader input1 = new BufferedReader(new InputStreamReader(ls.getInputStream()));
    String str = input1.readLine();
    /* Keep looping until we have read all of the output */
    while(str != null) {
    System.out.println(str);
    str = input1.readLine();
    } catch (java.io.IOException el) {
    System.err.println(el);
    import javax.swing.*;
    import java.awt.event.*;
    public class Main{
    JFrame frame;
    public static void main(String[] args){
    Main db = new Main();
    public Main(){
    frame = new JFrame("Show Message Dialog");
    JButton button = new JButton("Click Me");
    button.addActionListener(new MyAction());
    frame.add(button);
    frame.setSize(400, 400);
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    public class MyAction implements ActionListener{
    public void actionPerformed(ActionEvent e){
    JOptionPane.showMessageDialog(frame,"hello");
    }

    its pretty hard to read without code tags,
    if your questions is can i use this code in my new swing applications when i press a button
    sure you can you need to make your new program with actionlisterners, your button will then wait until you click on it,
    then you will call your old method when the button is clicked
    I think that what you want sorry if i got the wrong end of the stick

  • Runtime.getRuntime().exec("/usr/bin/env") crashes on Solaris

    I am trying to write a Java class to read environment variables on Solaris. I have read a few posts on this forum and it appears that other people have had no trouble in doing this. I have written the following code to execute the unix 'env' command and read in the standard input stream from the output.
    // start
    Process process = Runtime.getRuntime().exec("/usr/bin/env");
    try {
    process.waitFor();
    if (process.exitValue() != 0) {
    return "Process exited with non-zero status";
    catch (InterruptedException intexc) {
    return "ERROR: "+intexc.getMessage();
    BufferedReader br1 = new BufferedReader(new InputStreamReader(process.getInputStream()));
    // blah, blah, blah, code to parse input from process
    // end
    The problem that I am having is that the class crashes whenever it is run. I have substituted 'env' for a number of other commands and these work ok which makes me suspect that there is some percularity with the 'env' program. Also, the code appears to halt on the 'exec' so it is nothing to do with the reading of input, it is the actual execution of the command that it causing the problem.
    Does anyone have any experience of using 'env' in this way under Solaris or has anyone managed to develop a similar class? Any help greatly appreciated.
    Cheers,
    Jon.

    Found a solution to this in the bug database.
    Bug ID: 4098442

  • Unable to run certain commands on unix using the Runtime.getRuntime().exec(

    Hi Folks,
    I am unable to get any output if I try : Runtime.getRuntime().exec("who am i")
    however for Runtime.getRuntime().exec("pwd") I am getting the present working directory path !!!
    if I give Runtime.getRuntime().exec("echo $PATH") then instead of printing the path it prints $PATH instead !!! similarly it is unable to understand any of the special unix characters such as " or ' & is assuming it to be a literal instead.
    Any idea why this is happening ?? and any solution for the same
    regards
    Anand

    I don't think that Runtime.getRuntime().exec() spawns a shell it just executes the file that is specified in the string. ecause of this you can not use commands that are built-in in the shell directly nor use special shell characters. You must spawn your own shell, try something like this:
    Runtime.getRuntime().exec("sh");I'm sure you can add some switch to sh to execute a command by I am not using unix myself so I don't know how. Someone else have to help you with that. You can allways read the man-pages.

  • How to get return value from Java runtime.getRuntime.exec?

    I'm running shell commands from an Oracle db (11gr2) on aix.
    But, I would like to get a return value from a shell comand... like you get with "echo $?"
    I use a code like
    CREATE OR REPLACE JAVA SOURCE NAMED common."Host" AS
    import java.io.*;
    public class Host {
      public static int executeCommand(String command) {
        int retval=0;
        try {
            String[] finalCommand;
            finalCommand = new String[3];
            finalCommand[0] = "/bin/sh";
            finalCommand[1] = "-c";
            finalCommand[2] = command;
          final Process pr = Runtime.getRuntime().exec(finalCommand);
          pr.waitFor();
       catch (Exception ex) {
          System.out.println(ex.getLocalizedMessage());
          retval=-1;
        return retval;
    /but I do not get a return value... because I don't know how to get return value..
    Edited by: user9158455 on 22-Sep-2010 07:33

    Hi,
    Have your tried pr.exitValue() ?
    I think you also need a finally block that destroys the subprocess
    Regards
    Peter

Maybe you are looking for

  • How to find out the scructure of OID database

    Hello, I installed the OID on our server, but now I have to have access to the databse. There is no problem, but there are no primary or foreign keys in a database, so I can not find out the relations between the tables in OID-databse. How can I find

  • Offline and online synchronization

    Hello All , Any one has experience with offline online synchronization with live cycle or blazeds and adobe air ? I appreciate your response

  • Using numbering convention in DNG 8.7.1.311

    After filling out the dialog box directing DNG where to put the converted files, "Begin numbering" is grayed out. How can I access it to create the numbering I want?

  • Expensive SQL statements & no proper indexing INCLUDE LBSVAU14-BSVA FuncGrp

    Expensive SQL statements & no proper indexing INCLUDE LBSVAU14 - Function Group BSVA (Status management) Hi there Forum During a recent upgrade we have implemented EhP4 with relevant Support Packs. Our Early Watch Report nows highlights INCLUDE LBSVA

  • Heroes of Newerth - crashing OS X. also, fan problem.

    Everytime I play Hereos of Newerth, the system will freeze. Sometimes the gray screen comes up telling me to reboot, but sometimes it just freezes and forces me to hard reset. Is anyone else having this issue ? Also sometimes the CPU will hit 80 some