Why is Runtime.getRuntime().exec() not working in JSP?

Hi all,
I need to execute a command file from a JSP. I am using Tomcat 4.0.3.
Here is the code :
I just wanted to test if this will work, so tried to do run notepad.exe. But in my actual project, i need to run some other commands from a bat file or cmd file.
<%@ page import="java.util.*,java.io.*,java.net.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="tryexec" %>
//tryexec is a class which has the same java statements as in this jsp
<%     
Runtime r = Runtime.getRuntime();
String s3 = "C:\\WINNT\\explorer.exe";
String s4 = "C:\\bin\\open.cmd"; //inside open.cmd file , i have "notepad.exe"
r.exec(s3);
r.exec(s4);
/*     tryexec c = new tryexec();
     c.execTo(); // doesn't work
%>
I have a html page , when i click a button there , it will call the above jsp , and this jsp will execute the command file.
If i run the above java statements using a simple java program, it works fine, it opens a notepad and explorer window. but if i do the same thing in jsp, why doesn't it work? Is there any security problem? no exception is shown . Is it a problem with tomcat?
I also tried to import the java class in jsp and call the function, but still didnt work.
Please let me know whats the problem, and how to execute command files from jsp.
Thanks
Priyha

It would work with Java coz u r working on the same machine as the java class file.
While in case of JSP, it is like connecting to a different machine (even if the server is running on the same machine). If you do something like "net send user message" command in JSP or something other executable (just to test), you would see it to work.
I hope you understand my point here.
Write back if you have any issues.
Regards
Aruneesh

Similar Messages

  • Runtime.getRuntime.exec() not working when Tomcat is made a windows Sevice

    Hi,
    I am working on a web application which launches a exe file on subitting the form. I am using Apache Tomcat 4.0.6 to run the web application. Initially Tomcat was not made a windows service on my machine and when I launch an exe it is launching without any problems. I used the following command to launch the exe file:
    <code>
    Process p = Runtime.getRuntime().exec("C:\\Program Files\\Mercury Interactive\\WinRunner\\arch\\wrun.exe" + strWROptions);
    </code>
    The above command launches WinRunner on the local machine.
    without using tomcat if I just compile and run a test program with this command, the exe is launching perfectly. But, Once I made tomcat a windows service on my machine the exe is not launching.
    Also, a process is being created in the windows task bar named wrun.exe once I submit the form but WinRunner is not lauching on the desktop.
    Can any one please help and suggest me.
    Thanks,
    Ramesh

    The version of Java I am using is 1.4.2. Even without
    using the string array as you mentioned, the exe
    (wrun.exe) is launched on my desktop if I don't run
    Tomcat as a windows service. But the problem arises on
    making it a service :-(
    That is strange because going by the documentation what you have been using should never work. I can't test it though, I'm not on MSWindows at the moment..
    Now, when I use this string array convention, I am
    getting an error saying "The tool could not launch..
    some error occured".
    That's not a Java error message, it must come from WinRunner. This means that you have succesfully started WinRunner (great!) but something else is wrong; maybe the parameters you pass to it are incorrect.
    How would you run it on the command line? Like this?wrun -t "D:\L5_QE\L5A\Initial" -create_text_report on -runThat line executes the wrun program and passes it five parameters, not three. The first parameter is "-t", the second "D:\L5_QE\L5A\Initial", the third "-create_text_report", the fourth "on", and the fifth "-run". The array of strings that corresponds to that line isString[] command = {"C:\\Program Files\\Mercury Interactive\\WinRunner\\arch\\wrun.exe",
                    "-t", "D:\\L5_QE\\L5A\\Initial",
                    "-create_text_report", "on",
                    "-run"};

  • Runtime.getRuntime.exec() not working with through Servlet

    Hi ,
    I want to open a IE from servlet,I am using a Runtime.getRuntime.exec to open the browser ,but my servlet is executing but IE is not opening...Here i am using TomcatServer...Is any settings to be Done in TomcatServer.
    My Servlet code is
    public void doGet(HttpServletRequest request,
    HttpServletResponse response)
    throws IOException, ServletException
         String s1 = "C:/Program Files/Internet Explorer/IEXPLORE.EXE";
         String s2 = "http://192.168.0.149:8080/etk/etk3.htm";
         Runtime runtime = Runtime.getRuntime();
         runtime.exec(s1 + " " + s2);
    i know it is contrary to the purpose servlets are meant for.but i am using for different purpose..
    help me on this one...
    Thanks in Advance

    No, I am using the right path, I am sure. Also I tried giving the absolute path of the UserGuide.pdf. Still it cannot find. Please anyone try spawning an application from a different directory and lemme know your openion.
    Regards,
    Thomas.

  • Unable to execute Runtime.getRuntime().exec(

    Hello,
    I am new to Java programming and trying to execute (OS is Linux) an external jar File with the command:
    Runtime.getRuntime().exec("nohup java -jar SeismicAgents.jar &");It should start the SeismicAgents.jar and write the output to nohup.out.
    This works perfectly if I just enter the command at the command line.
    But upon starting it from within my program, the process seems to be started (I can see it when executin "ps aux"), but it is obviously not running as no input is written to nohup.out and the file which SeismicAgents.jar should generate is not generated.
    I also tried the following code:
    String cmd[] = {"nohup", "java", "-jar", "SeismicAgents.jar", "&"};
    Runtime.getRuntime().exec(cmd);But I am experiencing the same problem here.
    Executing something like
    Runtime.getRuntime().exec(ls);works without problems...
    Can anyone help?

    Runtime.getRuntime().exec("nohup java -jar
    SeismicAgents.jar &");Java does not interprete the '&' character. Neither does
    nohup. You would have to prefix this with /bin/sh -c, put
    the rest in quotes and, most importantly, redirect input
    and output somewhere. Without redirection, it is the task
    of your java program to feed the subprocess with input
    and drain its stdout and stderr buffers.
    Executing something like
    Runtime.getRuntime().exec(ls);works without problems...It is hard to believe this. Either it should be "ls" or
    ls is string variable containing the relevant string,
    but even then I would be surprised if you see any
    output on the command line. At least I don't get
    anything with public class bla {
      public static void main(String[] argv) throws Exception {
        Runtime.getRuntime().exec("ls");
    }If you don't want a "/bin/sh -c" hack, you may want to
    try http://www.ebi.ac.uk/~kirsch/monq-doc/monq/stuff/Exec.html .
    Harald.

  • Runtime.getRuntime().exec(cmd) not working

    I have created binary scrip to parse file from one format to another format and the file parser is available on Linux path and working fine when calling from command prompt but while calling this program from jsf or any any java form bean it adds some special charaters with program and throws IOException as belows
    calling command
    String[]     cmd={"delimiter",inputFile.toString(),outputFile.toString()};
    Process     p=Runtime.getRuntime().exec(cmd);
    it gives following error.
    java.io.IOException: delimiter@! : not found
    while calling this from jaav main application working fine.
    any suggestion would be appriciated.
    Cheers,
    dharmendra

    Thanks.
    I printed out whatever values are being passed and it is printing the right values on console and in log file and I also tried this command in stand alone application program an working fine. but when I call it from jsf form bean it adds ^@ at the end of first parameter and says ;
    IOException : delimiter^@ : not found
    i actually created the same copy as delimiter^@ and put it in same path directory with 777 mode.
    and now its working fine. but I did not know the reason why it change the name of first argument.
    Thanks,

  • 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                                                                                                                                                                                                                                                                                                                                                           

  • 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() does not work after JRE upgradation

    I have upgraded JRE from 1.3.0_02 to 1.3.1_15. After this upgrade, Runtime.getRuntime().exec() has suddenly stopped working. If I downgrade to 1.3.0_02, it starts working again.
    Please help.

    It has definitely forked, and this is the child process. It says so. If it was the parent process it would just show Java code related to launching processes. That does not involve PKCS11. After the fork there are two identical processes with the same stack: the child process of the fork goes on to replace itself with the target command via Unix exec(), which it doesn't look like it is succeeding at. The parent process doesn't do much at all, probably just housekeeping and then a Unix wait() for Process.waitFor() to hook into.

  • Runtime.getRuntime().exec(x) "Command not found"?

    Hello,
    I am attempting to run the following code in my java program.
    System.out.println("<!> gunzip -c " + curZippedFilePath + " | tar xf - --directory " + curMovedUnzippedPath;
    String unzipCommand[] = {"sh gunzip -c " + curZippedFilePath + " | tar xf - --directory " + curMovedUnzippedPath};
                  Process unzipChild = Runtime.getRuntime().exec(unzipCommand);
                 However, when it is run, I get the following message.
    <!> gunzip -c /gnm/apache/htdocs/GNM_Data/1c02.tgz | tar xf - --directory /gnm/GNM_Autoupdate/databaseUpdate/dataDump/1c02
    Exception in thread "main" java.io.IOException: java.io.IOException: gunzip -c /gnm/apache/htdocs/GNM_Data/1c02.tgz | tar xf - --directory /gnm/GNM_Autoupdate/databaseUpdate/dataDump/1c02: not found
            at java.lang.UNIXProcess.<init>(UNIXProcess.java:148)
            at java.lang.ProcessImpl.start(ProcessImpl.java:65)
            at java.lang.ProcessBuilder.start(ProcessBuilder.java:451)
            at java.lang.Runtime.exec(Runtime.java:591)
            at java.lang.Runtime.exec(Runtime.java:464)
            at DatabaseBackUpdate.main(DatabaseBackUpdate.java:49)Why is the gunzip command not found? Also, the command works when I try it in the shell. Why doesn't it work in the Java code?

    I got it!
    I needed to use the following without passing an array to the exec() function.
    String theCommand = "tar xfz " + curZippedFilePath + " -C " + dataDumpDir;
    Process unzipChild = Runtime.getRuntime().exec(theCommand);No onto another problem : (

  • Runtime.getRuntime().exec() does not return

    Hello,
    I am running into a case where the call to Runtime.getRuntime.exec(command) does not return. The scenario is that the main thread spawns another thread which calls the Runtime.exec(). Since the call does not return, both threads seems to be hung. The jstack output from the main thread shows
    ----------------- t@2 -----------------
    0xfeedab45 ___lwp_cond_wait + 0x15
    0xfeb4030d void os::PlatformEvent::park() + 0xa9
    0xfebadd48 void ObjectMonitor::wait(long long,bool,Thread*) + 0x26c
    0xfe770287 void ObjectSynchronizer::wait(Handle,long long,Thread*) + 0xef
    0xfe76ffbb JVM_MonitorWait + 0x20f
    0xfb20a032 * java.lang.Object.wait(long) bci:0 (Interpreted frame)
    0xfb20308d * java.lang.Thread.join(long) bci:38 line:1143 (Interpreted frame)
    0xfb20308d * java.lang.Thread.join() bci:2 line:1196 (Interpreted frame)
    0xfb20308d * DataLoader.checkThreadGroup() bci:92 line:316 (Interpreted frame)
    0xfb202f27 * DataLoader.checkTables(int) bci:1 line:336 (Interpreted frame)
    0xfb202f69 * DataLoader.runLoad(int, java.lang.String, java.lang.String, java.lang.String, com.sabre.fltsked.apm.util.FSIOHelper)
    ... more below ....
    So it is waiting for the spawned thread on a join()
    And the jstack dump for the thread that called exec() is
    ----------------- t@70 -----------------
    0xfeed7409 __lwp_park + 0x19
    0xfeed1be7 cond_wait_queue + 0x5e
    0xfeed1f64 cond_wait_common + 0x1db
    0xfeed20d2 condwait + 0x7b
    0xfeed20fd cond_wait + 0x21
    0xfeed2136 pthread_cond_wait + 0x1b
    0x9741082a soft_delete_object_cleanup + 0x57
    0x97410906 soft_delete_object + 0x5b
    0x97410953 soft_delete_all_objects_in_session + 0x2e
    0x97407b7a soft_delete_session + 0xec
    0x97407860 soft_delete_all_sessions + 0x3c
    0x97402525 finalize_common + 0x66
    0x974026ae softtoken_fini + 0x34
    0x974355f9 _fini + 0x21
    0xfefdd49a remove_hdl + 0x766
    0xfefd8be9 dlclose_core + 0xb1
    0xfefd8c1d dlclose_intn + 0x21
    0xfefd8c96 dlclose_check + 0x2a
    0xfefd8d00 dlclose + 0x38
    0x97480aeb pkcs11_slottable_delete + 0xb1
    0x9747c691 finalize_common + 0xe2
    0x9747c6e0 pkcs11_fini + 0x3e
    0x9747c3bf pkcs11_fork_child + 0x73
    0xfee628b8 postforkchild_handler + 0x2f
    0xfeeca9ec fork + 0x12e
    0xfe338029 Java_java_lang_UNIXProcess_forkAndExec + 0x395
    0xfb20a032 * java.lang.UNIXProcess.forkAndExec(byte[], byte[], int, byte[], int, byte[], boolean, java.io.FileDescriptor, java.io.FileDescriptor, java.io.FileDescriptor) bci
    :0 (Interpreted frame)
    0xfb202f69 * java.lang.UNIXProcess.<init>(byte[], byte[], int, byte[], int, byte[], boolean) bci:62 line:53 (Interpreted frame)
    0xfb20308d * java.lang.ProcessImpl.start(java.lang.String[], java.util.Map, java.lang.String, boolean) bci:182 line:65 (Interpreted frame)
    0xfb202f27 * java.lang.ProcessBuilder.start() bci:112 line:452 (Interpreted frame)
    0xfb202f27 * java.lang.Runtime.exec(java.lang.String[], java.lang.String[], java.io.File) bci:16 line:593 (Interpreted frame)
    0xfb202f27 * java.lang.Runtime.exec(java.lang.String, java.lang.String[], java.io.File) bci:69 line:431 (Interpreted frame)
    0xfb202f27 * java.lang.Runtime.exec(java.lang.String) bci:4 line:328 (Interpreted frame)
    0xfb202f27 *SQLLoad(java.lang.StringBuffer) bci:181 line:51 (Interpreted frame)
    0xfb202e61 *FSLoadThread.run() bci:84 line:54 (Interpreted frame)
    The command I am trying to exec is "sqlldr" and I do have it in my PATH variable. Why is that the call to exec does not return? Any ideas?
    This is on jdk1.6.0_17
    Thanks,
    Bijoy.

    It has definitely forked, and this is the child process. It says so. If it was the parent process it would just show Java code related to launching processes. That does not involve PKCS11. After the fork there are two identical processes with the same stack: the child process of the fork goes on to replace itself with the target command via Unix exec(), which it doesn't look like it is succeeding at. The parent process doesn't do much at all, probably just housekeeping and then a Unix wait() for Process.waitFor() to hook into.

  • Runtime.getRuntime().exec doesn't work

    I write in my program this line:
    p=Runtime.getRuntime().exec("/usr/bin/identify -verbose /tmp/cible.jpg > /tmp/cible.jpg.txt");
    But the file cible.jpg.txt is not created!
    Can you explain me?
    advance thanks!
    Best regards!!!

    It doesn't work because it is literally passing the "> /tmp..." characters as a command-line argument to the "/usr/bin/identify" program, as opposed to having the shell interpreter (which you're not invoking) interpret that to mean "redirect the output to this file".

  • 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);

  • Don't work Runtime.getRuntime().exec

    Hi. I've written a simple programm, but it don't work(sorry for my english:)):
    import java.io.*;
    class MsgFormat {
         static String hostname;
         static String message;
    public class jPopUp {
         public static void send(MsgFormat msg) {
              if(msg.message.length()!=0) {
                   if(msg.hostname.length()!=0) {
                        try {
                             Process proc = Runtime.getRuntime().exec("echo " + msg.message
                                                                                                                                      + " | smbclient -M " + msg.hostname);
                             } catch (java.io.IOException e) {
         public static void main(String[] args) {
              try
                   MsgFormat mess = new MsgFormat();
                   System.out.println("Enter hostname: ");
                   BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
                   mess.hostname = in.readLine();
                   System.out.println("Enter your message: ");
                   mess.message = in.readLine();
                   send(mess);
              catch (java.io.IOException e) {}
    }

    The exec method isn't a shell. Try with something like this:String[] exec = {"/bin/bash",
                     "-c",
                     "echo "+msg.message+" | smbclient -M "+msg.hostname};
    Process proc = Runtime.getRuntime().exec(exec);

  • 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

  • Strange behaviour of Runtime.getRuntime().exec(command)

    hello guys,
    i wrote a program which executes some commands in commandline (actually tried multiple stuff.)
    what did i try?
    open "cmd.exe" manually (administrator)
    type "echo %PROCESSOR_ARCHITECTURE%" and hit enter, which returns me
    "AMD64"
    type "java -version" and hit enter, which returns me:
    "java version "1.6.0_10-beta"
    Java(TM) SE Runtime Environment (build 1.6.0_10-beta-b25)
    Java HotSpot(TM) 64-Bit Server VM (build 11.0-b12, mixed mode)"
    type "reg query "HKLM\SOFTWARE\7-zip"" returns me:
    HKEY_LOCAL_MACHINE\SOFTWARE\7-zip
    Path REG_SZ C:\Program Files\7-Zip\
    i wrote two functions to execute an command
    1) simply calls exec and reads errin and stdout from the process started:
    public static String execute(String command) {
              String result = "";
              try {
                   // Execute a command
                   Process child = Runtime.getRuntime().exec(command);
                   // Read from an input stream
                   InputStream in = child.getInputStream();
                   int c;
                   while ((c = in.read()) != -1) {
                        result += ((char) c);
                   in.close();
                   in = child.getErrorStream();
                   while ((c = in.read()) != -1) {
                        result += ((char) c);
                   in.close();
              } catch (IOException e) {
              return result;
         }the second function allows me to send multiple commands to the cmd
    public static String exec(String[] commands) {
              String line;
              String result = "";
              OutputStream stdin = null;
              InputStream stderr = null;
              InputStream stdout = null;
              // launch EXE and grab stdin/stdout and stderr
              try {
                   Process process;
                   process = Runtime.getRuntime().exec("cmd.exe");
                   stdin = process.getOutputStream();
                   stderr = process.getErrorStream();
                   stdout = process.getInputStream();
                   // "write" the parms into stdin
                   for (int i = 0; i < commands.length; i++) {
                        line = commands[i] + "\n";
                        stdin.write(line.getBytes());
                        stdin.flush();
                   stdin.close();
                   // clean up if any output in stdout
                   BufferedReader brCleanUp = new BufferedReader(
                             new InputStreamReader(stdout));
                   while ((line = brCleanUp.readLine()) != null) {
                        result += line + "\n";
                   brCleanUp.close();
                   // clean up if any output in stderr
                   brCleanUp = new BufferedReader(new InputStreamReader(stderr));
                   while ((line = brCleanUp.readLine()) != null) {
                        result += "ERR: " + line + "\n";
                   brCleanUp.close();
              } catch (IOException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
              return result;
         }so i try to execute the commands from above (yes, i am using \\ and \" in java)
    (1) "echo %PROCESSOR_ARCHITECTURE%"
    (2) "java -version"
    (3) "reg query "HKLM\SOFTWARE\7-zip""
    the first function returns me (note that ALL results are different from the stuff above!):
    (1) "" <-- empty ?!
    (2) java version "1.6.0_11"
    Java(TM) SE Runtime Environment (build 1.6.0_11-b03)
    Java HotSpot(TM) Client VM (build 11.0-b16, mixed mode, sharing)
    (3) ERROR: The system was unable to find the specified registry key or value.
    the second function returns me:
    (1) x86 <-- huh? i have AMD64
    (2) java version "1.6.0_11"
    Java(TM) SE Runtime Environment (build 1.6.0_11-b03)
    Java HotSpot(TM) Client VM (build 11.0-b16, mixed mode, sharing)
    (3) ERROR: The system was unable to find the specified registry key or value.
    horray! in this version the java version is correct! processor architecture is not empty but totally incorrect and the reg query is still err.
    any help is wellcome
    note: i only put stuff here, which returns me strange behaviour, most things are working correct with my functions (using the Runtime.getRuntime().exec(command); code)
    note2: "reg query "HKLM\HARDWARE\DESCRIPTION\System\CentralProcessor\0" /t REG_SZ" IS working, so why are "some" queries result in ERR, while they are working if typed by hand in cmd.exe?

    ok, i exported a jar file and execute it from cmd:
    java -jar myjar.jar
    now the output is:
    (1) "" if called by version 1, possible to retrieve by version 2 (no clue why!)
    (2) "java version "1.6.0_10-beta"
    Java(TM) SE Runtime Environment (build 1.6.0_10-beta-b25)
    Java HotSpot(TM) 64-Bit Server VM (build 11.0-b12, mixed mode)"
    (3) C:\Program Files\7-Zip\
    so all three problems are gone! (but its a hard way, as i need both functions and parse a lot of text... :/ )
    thanks for the tip, that eclipse changes variables (i really did not knew this one...)

Maybe you are looking for

  • HT201343 Is there a way to stream video from one iOS device to another?

    My family and I are going on an extended vacation and we want to make sure the kids have enough videos to keep them busy on very long flights. I'm taking my MacBook Pro and was wondering if there's a way to stream video our different iOS devices with

  • 5 months after the exchange upgrade.....

    Evening, how normal is this.....got the email from BT at the end of March indicating that my exchange had been upgraded etc etc etc. However, for some reason I am still connecting at ADSL1 (my router doesnt actually display the modulation mode but si

  • Buttons on Master Page not exporting correctly

    I have a interactive catalog in InD CS5 with vector navigation buttons on the master page in the upper left hand corner. When I export this as an interactive pdf the buttons disappear. However if I copy the same buttons to different areas of the page

  • Updated firefox wants to use an uninstalled font for dialog boxes, how to change the font?

    I'm running Redhat and I just upgraded firefox from 3.0 to 17. Webpages display correctly, but the menu options and dialog boxes are empty boxes. I need to either install the font it's looking for, in which case I need to know what font it's trying t

  • Mp 600 skips lines

    mp 600 alternately prints 4 lines and then skips 4 lines over and over again in a document when printing in black ink.