Runtime.Exec for 'appref.ms' files

Hello!
I am using Runtime.exec to call an external application from java classes. These classes are in turn used by JSP.
The external application is an "Application Reference" type application in Windows, and has the extension appref.ms
From Glassfish logs, I can see the following error:
java.io.IOException: Cannot run program ""C:\Documents and Settings\Administrator\Start Menu\Programs\ProTeleCo\QuotEncrypt.appref-ms"": CreateProcess error=193, %1 is not a valid Win32 application
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:459)
    at java.lang.Runtime.exec(Runtime.java:593)
    at java.lang.Runtime.exec(Runtime.java:466)
    at list.CreateNew.runExternal(CreateNew.java:251)
    at list.CreateNew.CreateQuotationDR(CreateNew.java:222)
    at list.CreateNew.processRequest(CreateNew.java:88)
    at list.CreateNew.doPost(CreateNew.java:143)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:754)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
    at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:427)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:315)
    at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:287)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:218)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:94)
    at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:98)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:222)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:587)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1096)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:166)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:587)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1096)
    at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:288)
    at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:647)
    at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:579)
    at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:831)
    at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:341)
    at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:263)
    at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:214)
    at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:265)
    at com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWorkerThread.java:106)
Caused by: java.io.IOException: CreateProcess error=193, %1 is not a valid Win32 application
    at java.lang.ProcessImpl.create(Native Method)
    at java.lang.ProcessImpl.<init>(ProcessImpl.java:81)
    at java.lang.ProcessImpl.start(ProcessImpl.java:30)
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:452)
    ... 35 moreWhen I open a command window and type
"C:\Documents and Settings\Administrator\Start Menu\Programs\MyCompany\QuotEncrypt.appref-ms" <arg1> <arg2>
The program runs without problems.
I actually tried copying the QuotEncrypt.exe file that is built in the development environment to the server and give that as argument to Runtime.exec, but in that case the application seems to run (I use waitfor and the return value from waitfor) , return with 0, but it has no side effects. It does not even write to its log file.
Hence I am at a loss to what to do.
Appreciate any help,
Irem

And now the program hangs.
It seems to be time for code indeed:
String[] commands = {"C:\\WINDOWS\\system32\\cmd.exe", " /start ", Constants.QuotEncryptPath, " \""+qfile + "\"", Constants.encryptPassword};
  runExternal(commands);
      public static void runExternal(String commands[])
        try
            Runtime rt = Runtime.getRuntime();
            System.out.println("Execing ");
            String whole="";
            for(int i =0; i < commands.length ; i ++)
            whole = whole + commands;
System.out.println(whole);
Process proc = rt.exec(commands);
// any error message?
StreamGobbler errorGobbler = new
StreamGobbler(proc.getErrorStream(), "ERROR");
// any output?
StreamGobbler outputGobbler = new
StreamGobbler(proc.getInputStream(), "OUTPUT");
// kick them off
errorGobbler.start();
outputGobbler.start();
// any error???
int exitVal = proc.waitFor();
System.out.println("ExitValue: " + exitVal);
} catch (Throwable t)
t.printStackTrace();
import java.io.*;
import java.util.*;
* @author iaktug
class StreamGobbler extends Thread
InputStream is;
String type;
StreamGobbler(InputStream is, String type)
this.is = is;
this.type = type;
@Override public void run()
try
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line=null;
while ( (line = br.readLine()) != null)
System.out.println(type + ">" + line);
} catch (IOException ioe)
ioe.printStackTrace();
I got the code from the famous when Runtime.exec() won't. I am now suspecting there is something wrong with this part.
Essentially I want a very simple thing. The external program will run and the parent program will wait for it and get the return value.
I added the Stream stuff simply to prevent deadlock/hanging.
I am considering trying to get that out completely.
The server messages go as follows:....
Execing |#]
[#|2009-12-17T09:42:40.499+0400|INFO|sun-appserver2.1|javax.enterprise.system.stream.out|_ThreadID=878233;_ThreadName=httpSSLWorkerThread-8082-4;|
C:\WINDOWS\system32\cmd.exe /start "C:\Documents and Settings\Administrator\Start Menu\Programs\ProTeleCo\QuotEncrypt.appref-ms" "H:\QUOTATIONS\Quotations\In Progress\q00502.xls"1q2w3e|#]
[#|2009-12-17T09:42:40.499+0400|INFO|sun-appserver2.1|javax.enterprise.system.stream.out|_ThreadID=878234;_ThreadName=Thread-923673;|
OUTPUT>Microsoft Windows [Version 5.2.3790]|#]
[#|2009-12-17T09:42:40.499+0400|INFO|sun-appserver2.1|javax.enterprise.system.stream.out|_ThreadID=878234;_ThreadName=Thread-923673;|
OUTPUT>(C) Copyright 1985-2003 Microsoft Corp.|#]
[#|2009-12-17T09:42:40.499+0400|INFO|sun-appserver2.1|javax.enterprise.system.stream.out|_ThreadID=878234;_ThreadName=Thread-923673;|
OUTPUT>|#]

Similar Messages

  • Runtime.exec() - using cp and files with spaces on unix

    I'm using the Runtime.exec method to copy files in a unix environment. This works fine until there is a file where the name has spaces in it. I've read the article on the pitfalls of using runtime and how it breaks a string on white spaces and this is what is happening. I've also found another topic that was having the same problem, but they were using /usr/bin/dos2unix. I've tried putting quotes around the filename, but it still breaks on the first space. Any suggestions on how to get around this or another way of doing this would be greatly appreciated.
    An example of the os command string is:
    /usr/bin/cp /tmp/file with space.doc /docs
    Thanks!

    Hi!
    Well I dont have any Sun machine right here to try this but in windows It works great.
    Have you tried something like this ?
    import java.io.*;
    public class OSCopy {
        public static void main(String[] args) {
            try {
                String space = " ";
                String copycmd = "E:\\cp.cmd";
                String source = "E:\\File with space.txt";
                String destination = "E:\\tmp";
                String cmd = copycmd + space + "\"" + source + "\"" + space + destination;
                System.out.println("cmd: " + cmd);
                Runtime runtime = Runtime.getRuntime();
                Process copy = runtime.exec( cmd );
                BufferedReader reader = new BufferedReader( new InputStreamReader( copy.getInputStream()) );
                String line = null;
                while( (line = reader.readLine()) != null ) {
                    System.out.println( line );
            catch (Exception e) {
                e.printStackTrace();
    cp.cmd is a simple dos copy command
    copy %1 %2
    */good luck!

  • Runtime.exec - Too Many Open Files

    System version : Red Hat Enterprise Linux 2.4.21-47.ELsmp AS release 3 (Taroon Update 8)
    JRE version : 1.6.0-b105
    Important : the commands described below are launched from a Web application : Apache Tomcat 6.0.10
    Hello,
    I'm facing a problem already known, but appearantly never really solved ??!! ;)
    When I invoke many system commands with the 'Runtime.exec(...)' method, there are open files that are not released (I can see them with the "lsof" system command) .
    At the end, the unavoidable "too many open files" Exception.
    The lauched commands are "ssh ... " commands.
    In the topics relating to this problem, the solution is always to close all Streams / threads and to explicitely invoke the method "Process.destroy()".
    My problem is that this is what I do ! And I can't do more...
    Here is the code :
           Runtime rt = Runtime.getRuntime();
           Process process = rt.exec("ssh ...");
            // ProcessStreamHolder extends Thread and reads from the InputStream given in constructor...
            ProcessStreamHolder errorStream = new ProcessStreamHolder(process.getErrorStream());
            ProcessStreamHolder outputStream = new ProcessStreamHolder(process.getInputStream());
            errorStream.start();
            outputStream.start();
            exitValue = process.waitFor();
            try {
                errorStream.interrupt();
            } catch (RuntimeException e) {
                logger.warn("...");
            try {
                outputStream.interrupt();
            } catch (RuntimeException e) {
                logger.warn("...");
            try {
                process.getInputStream().close();
            } catch (RuntimeException e) {
                logger.warn("...");
            try {
                process.getOutputStream().close();
            } catch (RuntimeException e) {
                logger.warn("...");
            try {
                process.getErrorStream().close();
            } catch (RuntimeException e) {
                logger.warn("...");
            process.destroy();Does someone know if my code is wrong or if there's a workaround for me ?
    Thanks by advance !
    Richard.

    Don't interrupt those threads. Close the output stream first, then wait for the process to exit, then both threads reading the stdout and stderr of the process should get EOFs, so they should exit naturally, and incidentally close the streams themselves.

  • Strange behavior when using Runtime.exec() to run batch file

    I've been struggling with this for hours.
    I have a Swing application which upon clicking a button, I want to execute a batch file. This batch file itself uses a command window.
    When I use
    Runtime load = Runtime.getRuntime();
    load.exec("cmd /c start c:\\renew\\renew2\\bin\\win\\renew.bat");
    The program (Renew) will start up no problem, but when I exit Renew, the command window stays put. I want the command window to close. Running Renew stand-alone, upon closing Renew, it will exit the command window.
    When I use
    Runtime load = Runtime.getRuntime();
    load.exec("cmd /c c:\\renew\\renew2\\bin\\win\\renew.bat");
    or
    Runtime load = Runtime.getRuntime();
    load.exec("c:\\renew\\renew2\\bin\\win\\renew.bat");
    When I press the button, sometimes the Renew application will come up right away, sometimes the Renew application will come up after a very long delay, and most times, the Renew application will only come up after I have closed the Swing frame where the button is located. When I use this code, the command window that Renew uses is never visible.
    What I want is to simply have the Renew application behave the same exact way launching from my Swing application as when Renew is being run standalone.
    Any suggestions? Thanks so much.
    Sincerely,
    Will

    Getting rid of start makes the startup time very variable. Sometimes it starts up right away, sometimes after many minutes, most times only after I close my application.
    Thanks, Any other suggestions?
    (BTW, I have read the famous "When Runtime.exec() won't" article, and have tried its suggestions to no avail)
    Message was edited by:
    willies777

  • Using runtime.exec to zip some files

    Hi,
    I am using runtime.exec to try to automatically zip a bunch of files on a server. However, it does not seem to be working.
    Before I execute the command, I save the zip command in a string. I then print the string to a log file, and then execute the runtime zip command. But nothing happens.
    Yet, when I copy the string from the log, and paste it in a terminal, it properly creates the zip files. So, I know I have the correct command string, it just does not seem to be working within the java application. Also, the command string uses fully qualified directories, so it is not a directory issue.
    I am using ubuntu linux.
    Any ideas?
    -Adam

    adamSpline wrote:
    Hi,
    I am using runtime.exec to try to automatically zip a bunch of files on a server. However, it does not seem to be working.
    Before I execute the command, I save the zip command in a string. I then print the string to a log file, and then execute the runtime zip command. But nothing happens. Within Runtime.exec() any command does not run in a shell and I bet you use wild cards and/or other commands to be interpreted by a shell which will not be interpreted since there is no shell. And, since you don't mention error messages or the return code, I will also bet you don't process the Process stdout , stderr and the return code properly.
    It looks to me like you have fallen for at least two for the traps in [http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html|http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html].
    >
    Yet, when I copy the string from the log, and paste it in a terminal, it properly creates the zip files. So, I know I have the correct command string, it just does not seem to be working within the java application. Also, the command string uses fully qualified directories, so it is not a directory issue.
    I am using ubuntu linux.
    Any ideas?I agree with 'masijade' - use the built in Java classes.
    >
    -Adam

  • Runtime.exec() for different Windows versions ?

    Hello all.
    I'm currently developing a Java program that uses Runtime.exec() to launch a MS-DOS application (the old MS-Kermit). It works fine under Windows ME and Java 1.3.1 but the very same code fails to work under Windows 2000. That's very bad for me, since my program should work on all windows platforms from 95 up to XP (and NT).
    My question is : can I trust Runtime.exec() or am I damned to write different versions of the same command for different operating systems ?
    Thanks.

    Runtime is not os independent, so yes, it has to accomodate the os differences. There is an enhancement request on the subject, tho.
    Search the forums, there is code that handles the differences posted.

  • Make can't recursively call Make when run from Runtime.exec (for some user)

    This one is a little complicated. The afflicted platform is Mac OS X. It works fine on Linux, it seems, and even then, it does work for some Mac OS X users...
    First, the setup. I have a Java program that has to call GNU Make. Then, GNU Make will recursively call Make in some subdirectories. This results in the following Java code:
    String make = "make"; //on windows, I have this swapped with "mingw32-make"
    String workDir = ...; //this is programmatically detected to be the same folder that the parent Makefile is in
    Runtime.getRuntime().exec(make,null,workDir);This calls make on a Makefile which has the following line early on to be executed (this is only a snippet from the makefile):
    cd subdirectory && $(MAKE)When I fetch the output from the make command, I usually get what I expect: It cd's to the directory and it recursively calls make and everything goes smoothly.
    However, for one particular user, using Mac OS X, he has reported the following output:
    cd subdirectory && make
    /bin/sh: make: command not found
    make: *** [PROJNAME] Error 127Which is like, kinda hurts my head... make can't find make, apparently.
    I've gotten some suggestions that it might be due to the "cd" command acting wonky. I've gotten other suggestions that it may be some strange setup with the env variables (My Mac developer is implementing a fix/workaround for 'environ', which is apparently posix standard, but Mac (Mr. Posix Compliance...) doesn't implement it. When he finishes that, I'll know whether it worked or not, but I get the feeling it won't fix this problem, since it's intended for another area of code entirely...
    Also worth mentioning, when the user calls "make" from the terminal in said directory, it recurses fine, getting past that particular line. (Later on down the road he hits errors with environ, which is what my aforementioned Mac dev is working on). Although calling "make" by hand is not an ideal solution here.
    Anyways, I'm looking for someone who's fairly knowledgeable with Runtime.exec() to suggest some way to work around this, or at least to find out that perhaps one of the User's settings are wonked up and they can just fix it and have this working... that'd be great too.
    -IsmAvatar

    YoungWinston
    YoungWinston wrote:
    IsmAvatar wrote:
    However, for one particular user, using Mac OS X, he has reported the following output:One particular user, or all users on Mac OS?In this case, I have two mac users. One is reporting that all works fine. The other is reporting this problem.
    cd subdirectory && make
    /bin/sh: make: command not found
    make: *** [PROJNAME] Error 127Which is like, kinda hurts my head... make can't find make, apparently.If that is being reported on the command line, then I'd say that make wasn't being found at all.If make isn't being found, then who's interpreting the Makefile?
    It's also just possible that the make script on Mac isn't correctly exporting its PATH variable, though it seems unlikely, since this would surely have been reported as a bug long ago.
    I've gotten some suggestions that it might be due to the "cd" command acting wonky...Also seems unlikely. 'cd' has been around since shortly after the K-T extinction event.
    WinstonBy "acting wonky", I mean being given a bad work directory or some such, such that it's not changing to the intended directory.
    Andrew Thompson
    Andrew Thompson wrote:
    (shudder) Read and implement all the recommendations of "When Runtime.exec() won't" (http://www.javaworld.com/jw-12-2000/jw-1229-traps.html).
    Already read it. I already know the dreadful wonders of Runtime.exec. But in this case, it's been working fine for us up until one Mac user reported that make can't find make.
    Also, why are you still coding for Java 1.4? If you are not, use a ProcessBuilder, which takes a small part of the pain out of dealing with processes.Usually I do use a ProcessBuilder. I noticed that it usually delegates to Runtime.exec() anyways, and seeing as I didn't need any of the additional functionality, I decided to just use Runtime.exec() in this particular case.
    jschell
    jschell wrote:
    So print thos env vars, in your app and when the user does it.I'll look into that. It's a good start.
    -IsmAvatar

  • Runtime.exec() for openning a browser

    hey guys!!
    I could open a browser using a runtime.exec(). once i have opened it can i use the process.getOuputStream() method to read what is there in the browser.
    How do i communicate with the browser?
    -karthek

    No, getOutputStream will read only what the program writes to standard output. Typically, GUI programs don't even use standard output. The only way you can communicate with processes started by Runtime.exec that I know of is with the Process class.

  • Reader 9.3 produces Runtime error for all .pdf files on hard drive and email

    Does anyone have a resource that can show me how to eliminate a runtime error with Reader 9.3.1, Windows XP w/ SP3 and IE7. I have recently had all .pdf files located on my hard drive and in emails refuse to open because of this message:
    "Runtime Error!
    Program C:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32.exe
    This application has requested the Runtime to terminate it in an unusual way.  Please contact the application's support team for more information."
    So far, I have uninstalled and reinstalled Reader 9.3 from the website; added update 9.3.1 and tried to reopen files with no success.
    My organization sends a ton of .pdf files and it is not good when you can't open them for review and action.

    Hi All,
    Although I don't normally post in forums, I thought it prudent to lay this matther to rest.  I have tested the following solution:
    It appears that Adobe Reader likes to check access to each parent folder as well as the actual application data folder.  Apparantly there are other programs that also do similar things. As a result if you have your appdata redirected to \\server1\profiles\%username%\appdata adobe reader would first try directly access \\server1\profiles.  If the user does not have to Traverse folder permission, this fails. Typically you will need to change your permissions on you profile share from:
    -                   Users - Read Attributes (Apply to: This folder, subfolders and files)
    -                   Users - Read Extended Attributes (Apply to: This folder, subfolders and files)
    -                  Users - Create Folders/Append Data (Apply to: This folder, subfolders and files)
    -                   Users - Read Permissions (Apply to: This folder, subfolders and files)
    To the share permissions suggested by Microsoft in KB 274443:
    -                   Everyone - Create Folder/Append Data (Apply onto: This Folder Only)
    -                   Everyone - List Folder/Read Data (Apply onto: This Folder Only)
    -                   Everyone - Read Attributes (Apply onto: This Folder Only)
    -                   Everyone - Traverse Folder/Execute File (Apply onto: This Folder Only)
    Hopefully this helps everyone.

  • I can not use the Runtime.exec() to open a file

    hi,
    i use java to open a pdf file like this:
    Runtime.getRuntime().exec("start c:/example.pdf");
    it works ok,but when i use java web start it do nothing,
    pls help me,why it can not work.
    thanks!

    I'm doing this with my app (getting access to the local filesystem and launch applications) and it works just fine.
    Things to do:
    1)
    Make sure your app is signed.
    (I used jarsigner to sign my jar file, comes with the j2se)
    2)
    Make sure in your .jnlp file that you are allowed to acces the filesystem, check your <security tags>
    <security>
    <all-permissions/>
    </security>
    3)
    From within the app try this to launch Acrobat Reader (win2000):
    Process pro = Runtime.getRuntime().exec("cmd.exe /C start acrord32");
    pro.waitFor();
    if (pro.exitValue() != 0)
    throw new IOException("AcrobatReader not installed");
    pro.waitFor() awaits your interaction with the filesystem, like closing an error popup dialog if os cannot find your file.
    When returning into your app, then check the exitValue. in windows, the exitvalue 1 is returned if the the file is missing. 0 if ok!
    I'm throwing an exception to handle further actions like opening a browser window with a given url to download the program.

  • Runtime.exec for launching a folder.

    Hi everyone,
    At the end of my application I need to launch a folder with all the output files. I tried with this code:
             try
                Runtime.getRuntime().exec("cmd start " + f.getAbsolutePath());
             catch (Exception eh){
                eh.printStackTrace();
             }And it works, the problems is that the application never ends, until the user closes the launched folder.
    I want to finish the application without to close the launched folder, somebody knows how to do this?
    -Daniel
    Edited by: zkropotkine on Feb 14, 2008 10:38 AM

    I resolved the problem...

  • Issue in using Runtime.exec for service in linux

    Hi,
    I have a problem in executing my own service through java6 on linux operating system.
    I have created a UI (user interface) which contains a button. On clicking that button my own service gets executed successfully. But the problem is that when I close my UI, my service gets stopped. I want that it should keep running even when the UI gets closed.
    I am using this command to start my service in ActionListener:
    Runtime.getRuntime().exec("service myservice start");Am I missing something here?
    Is this the expected behavior of exec()?

    You need to use something along the lines of
            String[] command =
                "bash", "-c", "xemacs > /dev/null 2>&1 &"
            Process p = Runtime.getRuntime().exec(command);
            Thread stderr = new StreamGobbler(p.getErrorStream(), "stderr");
            stderr.setDaemon(true);
            stderr.start();
            Thread stdout = new StreamGobbler(p.getInputStream(), "stdout");
            stdout.setDaemon(true);
            stdout.start();
            int exitCode = p.waitFor();
            System.out.println("Exit code = " + exitCode);where the StreamGobbler class is taken from [http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html|http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html]. You should read all the 4 sections of this article.

  • Runtime.exec() with .bat-files in a jar

    Hi All,
    I've written a java-Program, which calls .bat-files per Runtime.exec() for some OS-specific tasks.
    Everything works fine, but if I want to pack the whole code and the .bat-files into several jars, I can't get the bat-files to run. I have tried to get it to work with "getClass().getResource()" as I do the same for my Images, and the returned URL seems to be OK so far (something like jar:file:/c:/test.jar! testpkg/test.bat). I converted this URL into a String and tried to run Runtime.exec() with it, but I always get a Runtime-Exception.
    The String looks exactly like the URL, when I print them to console.
    These bat-files are essential for the application and I would not try to pack them into a jar if I hadn't to distribute this application as a signed applet to unknown users, too.
    I hope there is anyone out there who can tell me if and how it is possible to run an external program out of java, which is packed into a jar, so thanx in advance to any helpful replies.
    acdeka

    You can't run the .bats simply because the shell can't access it. You tell it to run a file that simply doesn't exist in the OS.

  • Execute java class from a batch file called from runtime.exec

    Hi.
    I don´t know if this question fits here.
    I wan´t to execute a batch file (on Win XP) with runtime.exec. That batch file will execute another java program.
    I have the following code:
    Resolutor.java
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    public class Resolutor {
          * @param args
         public static void main(String[] args) {
              // TODO Auto-generated method stub
              Runtime r = Runtime.getRuntime();
              //String[] command = { "cmd.exe", "/C",".\\lanzar.bat .\\ .\\ 001.res:001.dtt" };
              String[] command = { "cmd.exe", "/C",".\\tarea\\lanzar.bat " + args[0] + " " + args[1] + " " + args[2]};
              try {
                   //Process proceso = Runtime.getRuntime().exec("lanzar.bat");
                   Process proceso = Runtime.getRuntime().exec(command);
                   InputStream stderr = proceso.getErrorStream();
                InputStreamReader isr = new InputStreamReader(stderr);
                BufferedReader br = new BufferedReader(isr);
                String line = null;
                System.out.println("<ERROR>");
                while ( (line = br.readLine()) != null)
                    System.out.println(line);
                System.out.println("</ERROR>");
                   int exitVal = proceso.waitFor();
                   System.out.println("EXITVAL: " + exitVal);
              } catch (IOException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
              } catch (InterruptedException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
    }lanzar.bat
    java Lanzador %1 %2 %3Lanzador.java
    import java.util.Vector;
    public class Lanzador {
          * @param args
         public static void main(String[] args) {
              // TODO Auto-generated method stub
              Repetitiva rpt=new Repetitiva();
              String rutaFicheros=args[0];
              String rutaResultado=args[1];
              String[] ficheros=args[2].split(":");
              Vector<String> ficheroDatos=new Vector<String>();
              for(int i=0;i<ficheros.length;i++){
                   ficheroDatos.add(ficheros);
                   System.out.println(ficheros[i]);
              System.out.println("RUTA DE FICHEROS: " + rutaFicheros);
              System.out.println("RUTA DE RESULTADOS: " + rutaResultado);
              System.out.println("CALCULAR");
              rpt.setRepetitiva(ficheroDatos, rutaFicheros, rutaResultado);
              rpt.calcular();
    }I´ve got Resolutor.class in /res and the other two files (and the rest of the files for running) in /res/tarea.
    If I execute /res/tarea/lanzar.bat from the command line everything works fine, it calls java and runs lanzador without problem.
    The problem comes when I try to execute the batch file via Resolutor.class. It executes the batch file without problem, but it throws a *java.lang.NoClassDefFoundError: Lanzador* when launching the new java application.
    Any ideas of how can I solve that problem. (It must do it via batch file).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    Well, I tried putting in the bat file java -classpath .\tarea Lanzador %1 %2 %3 and didn´t work.
    I ve tried the bat modification, and the directory in x.txt is k:\res instead of k:\res\tarea.
    I´ve tried to modifiy it to java .\tarea\Lanzador and didn´t work so I have put a cd like the following and it appears to work.
    cd tarea
    java Lanzador %1 %2 %3Thanks for the replies.

  • Runtime.exec--problems writing to external file

    Hi. I went to http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html, and am still quite confused regarding the use of Runtime.exec, for my purposes. I want to decompile a CLASS file using javap, and then write that to a TXT file, for easier reading/input to JAVA. Now, I use the following code (a modification of what I got from http://www.mountainstorm.com/publications/javazine.html, as the "traps" article's sample code is WAY too confusing--they say the compiler had the output sent to text.txt, without even showing how in the source code they did that), but it hangs up. Modifications to the string array cause different results, such as showing the javap help menu, or saying that the class wasn't found, but I think the way I did the array here is right:
    import java.util.*;
    import java.io.*;
    public class Test {
            try {
             String ls_str;
                String[] cmd = {"C:\\j2sdk1.4.2_04\\bin\\javap", "-c", "-classpath", "H:\\Java\\metricTest", "metricTest > blah.txt", ""};
                Process ls_proc = Runtime.getRuntime().exec(cmd);
             // get its output (your input) stream
             DataInputStream ls_in = new DataInputStream(
                                              ls_proc.getInputStream());
             try {
              while ((ls_str = ls_in.readLine()) != null) {
                  System.out.println(ls_str);
             } catch (IOException e) {
              System.exit(0);
         } catch (IOException e1) {
             System.err.println(e1);
             System.exit(1);
         System.exit(0);
    }

    Also, jesie, I realize that's what I need...the only
    problem is, the name "test.txt" is nowhere to be found
    in the source code! lolLooks like I have to explain this, then.
    When you look at a Java program you'll notice that it always has a "main" method whose signature looks like this:public static void main(String[] args)When you execute that program from the command line, it takes whatever strings you put after the class name and passes them to the main program as that array of strings. For example if you run it likejava UselessProgram foo bar hippothen the "java" command takes the three strings "foo", "bar", and "hippo" and puts them into that args[] array before calling the "main" method.
    That means that inside the "main" method in this case, "args[0]" contains "foo", "args[1]" contains "bar", and "args[2]" contains "hippo".
    Now go back to the example and see how it lines up with that.

Maybe you are looking for

  • Yahoo messenger no longer shows up in yahoo mail after Ver 9 update.

    I use my yahoo mail for email and yahoo messenger. It worked well until the update to version 9 of Firefox. The messenger part does not show up in my yahoo email now. Other people can still see that I am online as they will send me an IM and the tab

  • Pull data and store in a UI  ... please help

    "Code to Pull data from ASCP, OM and Inventory, consolidate the data and push the data to UI " this is my task, and i'm kinda new to API's and data pulling ... please help me with the steps ..and procedure to perform this task ... Thanks in advance E

  • Sense Error burning DVD disc in Toast

    HI there, I'm trying to burn an ISO (DVD R disc) using Roxio's Toast Titanium and no matter what brand of disc I use, I keep getting "The drive reported an error: Sense Key = MEDIUM ERROR Sense Code = 0x73, 0x03. I'm using a 2008 15inch MacBook Pro,

  • Issue in exposing MySQL table as OData in SMP 3.0

    Experts, I have created OData entity to represent a table in mysql & deployed in SMP3.0. Also created a security profile with same name as Service Namespace given while deploying.  Mysql connector jar is placed in SMP pickup folder. In gateway cockpi

  • Report Query - Download data - converts special characters

    When I'm doing a select from a table which has a "<" or ">" sign it is being changed to < or > when I view the XML data that is being downloaded. Is there any way to prevent it from doing this?