Runtime.exec() fails to run "javac" with "*.java" as arguments

Hello,
I am observing that Runtime.exec() consistently fails to execute "javac" when the Java files to be compiled are specified as "*.java". It fails with the following error:
javac: file not found: /home/engine931/*.java
Usage: javac <options> <source files>
The same command used for Runtime.exec() runs fine from a the command shell. Is this is known problem with the Runtime class on UNIX, because it works fine on Windows.
Any advise is appreciated.
Thanks,
Ranjit

Your shell is expanding the command when you run javac from the shell. Try constructing your Runtime parameters so that your shell is executed, which then executes javac.
The specific behavior is entirely dependent on the command interpreter that's used.

Similar Messages

  • Runtime.exec() fails sometime to execute a command

    Hello,
    I have a program thats using Runtime.exec to execute some external programs sequence with some redirection operators.
    For e.g, I have some command as follows;
    1 - C:\bin\IBRSD.exe IBRSD -s
    2 - C:\bin\mcstat -n @punduk444:5000#mc -l c:\ | grep -i running | grep -v grep |wc -l
    3 - ping punduk444 | grep "100%" | wc -l
    ...etc.
    These command in sequence for a single run. The test program makes multiple such runs. So my problem is sometimes the runtime.exec() fails to execute some of the commands above (typically the 2nd one). The waitFor() returns error code (-1). That is if I loop these commands for say 30 runs then in some 1~4 runs the 2nd command fails to execute and return -1 error code.
    Can some one help me out to as why this is happening? Any help is appreciated
    Thanks,
    ~jaideep
    Herer is the code snippet;
    Runtime runtime = Runtime.getRuntime();
    //create process object to handle result
    Process process = null;
    commandToRun = "cmd /c " + command;
    process = runtime.exec( commandToRun );
    CommandOutputReader cmdError = new CommandOutputReader(process.getErrorStream());
    CommandOutputReader cmdOutput = new CommandOutputReader(process.getInputStream());
    cmdError.start();
    cmdOutput.start();
    CheckProcess chkProcess = new CheckProcess(process);
    chkProcess.start();
    int retValue = process.waitFor();
    if(retValue != 0)
    return -1;
    output = cmdOutput.getOutputData();
    cmdError = null;
    cmdOutput = null;
    chkProcess = null;
    /*******************************supporting CommandOutputReader class *********************************/
    public class CommandOutputReader extends Thread
    private transient InputStream inputStream; //to get output of any command
    private transient String output; //output will store command output
    protected boolean isDone;
    public CommandOutputReader()
    super();
    output = "";
    this.inputStream = null;
    public CommandOutputReader(InputStream stream)
    super();
    output = "";
    this.inputStream = stream;
    public void setStream(InputStream stream)
    this.inputStream = stream;
    public String getOutputData()
    return output;
    public void run()
    if(inputStream != null)
    final BufferedReader bufferReader = new BufferedReader(new InputStreamReader(inputStream), 1024 * 128);
    String line = null;
    try
    while ( (line = bufferReader.readLine()) != null)
    if (ResourceString.getLocale() != null)
    Utility.log(Level.DEBUG,line);
    //output += line + System.getProperty(Constants.ALL_NEWLINE_GETPROPERTY_PARAM);
    output += line + "\r\n";
    System.out.println("<< "+ this.getId() + " >>" + output );
    System.out.println("<< "+ this.getId() + " >>" + "closed the i/p stream...");
    inputStream.close();
    bufferReader.close();
    catch (IOException objIOException)
    if (ResourceString.getLocale() != null)
    Utility.log(Level.ERROR, ResourceString.getString("io_exeception_reading_cmd_output")+
    objIOException.getMessage());
    output = ResourceString.getString("io_exeception_reading_cmd_output");
    else
    output = "io exeception reading cmd output";
    finally {
    isDone = true;
    public boolean isDone() {
    return isDone;
    /*******************************supporting CommandOutputReader class *********************************/
    /*******************************supporting process controller class *********************************/
    public class CheckProcess extends Thread
    private transient Process monitoredProcess;
    private transient boolean continueLoop ;
    private transient long maxWait = Constants.WAIT_PERIOD;
    public CheckProcess(Process monitoredProcess)
    super();
    this.monitoredProcess = monitoredProcess;
    continueLoop =true;
    public void setMaxWait(final long max)
    this.maxWait = max;
    public void stopProcess()
    continueLoop=false;
    public void run()
    //long start1 = java.util.Calendar.getInstance().getTimeInMillis();
    final long start1 = System.currentTimeMillis();
    while (true && continueLoop)
    // after maxWait millis, stops monitoredProcess and return
    if (System.currentTimeMillis() - start1 > maxWait)
    if(monitoredProcess != null)
    monitoredProcess.destroy();
    //available for garbage collection
    // @PMD:REVIEWED:NullAssignment: by jbarde on 9/28/06 7:29 PM
    monitoredProcess = null;
    return;
    try
    sleep(1000);
    catch (InterruptedException e)
    if (ResourceString.getLocale() != null)
    Utility.log(Level.ERROR, ResourceString.getString("exception_in_sleep") + e.getLocalizedMessage());
    System.out.println(ResourceString.getString("exception_in_sleep") + e.getLocalizedMessage());
    else
    System.out.println("Exception in sleep" + e.getLocalizedMessage());
    if(monitoredProcess != null)
    monitoredProcess.destroy();
    //available for garbage collection
    // @PMD:REVIEWED:NullAssignment: by jbarde on 9/28/06 7:29 PM
    monitoredProcess = null;
    /*******************************supporting process controller class *********************************/

    Hi,
    Infact the command passed to the exec() is in the form of a batch file, which contains on of these commands. I can not put all commands in one batch file due to inherent nature of the program.
    But my main concern was that, why would it behave like this. If I run the same command for 30 times 1~3 times the same command can not be executed (returns with error code 1, on wiun2k pro) and rest times it works perfectly fine.
    Do you see any abnormality in the code.
    I ahve used the same sequence of code as in the article suggested by
    "masijade". i.e having threads to monitor the process and other threads to read and empty out the input and error streams so that the buffer does not get full.
    But I see here the problem is not of process getting hanged, I sense this because my waitFor() returns with error code as 1, had the process hanged it would not have returned , am I making sense?
    Regards,
    ~jaideep

  • Runtime.Exec() fails -- Through java stored procedure in Oracle8i

    HI,
    I HAVE A JAVA STORED PROCEDURE WHICH EXECUTES
    A HOST COMMAND USING Runtime.Exec().
    BUT IT IS NOT WORKING.
    RIGHTS FOR THE USER HAVE BEEN GIVEN USING
    Dbms_grant_persmission(). The database in on
    SUN SOLARIS. THE EXITVALUE OF THE RUNTIME.EXEC COMMAND IS 255(SEGMENTATION
    ERROR - CORE DUMPED).
    PLEASE LET ME KNOW WHERE THE PROBLEM LIES. THE FUNCTION IS WORKING WELL IF THE DATABASE IS ON NT PLATFORM BUT FAILS TO WORK WHEN I STORED THE PROCEDURE IN A DATABASE RUNNING ON SUN SOLARIS AND TRIED TO EXECUTE A SOLARIS COMMAND THROUGH THE PROCEDURE.
    Thanks for ur interest!
    with best regards,
    Mathan

    I have similar problem on HP-UX, I would appreciate if you
    somehow were able to solve it.
    Thanks
    Rahul Shah

  • Runtime.exec() fails

    Hi,
    I have a process with many executables which work together to copy a script to another machine, execute it and get back the results. I am using Runtime.exec to execute the process. The files are stored in the directory "/opt/mx/myDir".
    Below are two scenarios. One works and the other doesnt.
    1. Working case.
    #cd /opt/mx/myDir
    #java myJavaClass.
    2. Failing case.
    #java myJavaClass.
    The issue is that myJavaClass is part of another project and hence I cannot "cd" to /opt/mx/myDir. So it executes at some directory and fails.
    Hence I tried ProcessBuilder.directory(file) - This fails too.
    I have no logs or anything as the other process is not mine.
    Any help on debugging this will be great.
    Thanks.

    Apologies if this is too obvious, but is your command
    #java myJavaClass.
    or
    java myJavaClass
    The trailing period is wrong.

  • Running javac from java

    I have created a program which generates code that needs to be compiled while running the program. Currently I am doing it using Runtime.exec() but I don't like the dos window that appears. If there is any way to hide the dos window or compile another way, let me know? Thanks
    This is how I am currently doing it:
    String exec = "javac " + Filename;
    Runtime r = Runtime.getRuntime();
    Process p = r.exec(exec);
    try {
    int exitVal = p.waitFor();
    if (exitVal != 0){
    InputStream stderr = p.getErrorStream();
    InputStreamReader isr = new InputStreamReader (stderr);
    BufferedReader br = new BufferedReader(isr);
    String line = null;
    while ( (line = br.readLine()) != null)
    Sytem.out.println(line);
    catch (java.lang.InterruptedException ie){ie.printStackTrace();}

    You can do the following:
    1. Use class generation API to generate ready class. But you must care about syntax or VM will generate errors on load.
    2. Use compiler in SDK from Java. Below is my code:
          File classesDir = new File(home, "classes");
          File javaSource = new File(source.getParent(), className+".java");
                new sun.tools.javac.Main(System.err, "javac").
                  compile(
                    new String[]{
                      "-d",
                      classesDir.getPath(),
                      "-classpath",
                      classesDir.getPath(),
                      javaSource.getPath()
                  );where javaSource is file to be compiled and classesDir is a directory where compiler emits classes.
    The first way is faster, but the second is preferred because you can see intermediate sources. Oh, in second case you must have /java_home/lib.tools.jar file in your classpath. Thats all, enjoy :))

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

  • Access JAR File while running App with Java Web Start

    Hello guys,
    I want to delpoy my application so that I can run it when I click on the appropriate button in a web page.
    I have a Jar file for all the files that the app needs. No, not all of the files are included.
    Indeed, I use JAR files such jdom.jar or postgres...jar that I must use in within my application.
    How can I access these JAR files knowing that I can't point to files in a JAR file A from within a JAR file B, if the JAR file B contains the JAR file A?
    The main JAR file that I put on the web server can be seen as the JAR file B and the other JAR files must be stored somewhere for the java classes within the main JAR file to have access to them.
    I wonder whether there is another way to structure the project.
    Thanks.

    Hi Andrew.
    I have followed your suggestions and here is what my .jnlp file look like:
    <tt>
    <?xml version="1.0" encoding="utf-8"?>
    <jnlp spec="1.0+" codebase="http://localhost:8080/koedops" href="beta.jnlp">
         <information>
              <title>KOEDOPS</title>
              <vendor>Pr. Fischer</vendor>
              <homepage href="http://localhost:8080/" />
              <description>Downloading koedops with Java Web Start</description>
         </information>
         <resources>
              <j2se version="1.6+" />
              <jar href="beta.jar" main="true"/>
              <jar href="jcalendar-1.3.3.jar" />
              <jar href="jdom.jar" />
              <jar href="postgresql-8.4-701.jdbc4.jar" />
         </resources>
         <application-desc main-class="general.Application" />
    </jnlp>               
    </tt>
    The three other jar-files reside in the same directory as the .jnlp file and the beta.jar file on the tomcat server.
    When I launch the application though nothing happens upon the download. In contrast, if I change the main class to a class file that requires no extra library, it runs perfectly.
    I can't be sure whether the jar-files are successfully accessed.
    Regards.
    Edmond

  • Elementary Question--Running javac with SDK 5

    When I downloaded the SDK 5, the File path went as follows: C:\Sun\SDK. Is this correct? And if so, how should I change the path so that I can run javac in command prompt? Right now it wants to use the jdk1.4, which I have deleted.

    Hello,
    I have the same application server installation path and it is working fine. I am developing EJB with swing, servlet and JSP. It will work. But changing the default paths could end you with problems. I believe the software you downloaded is one that comes with both the application server 9 and JDK 5 together.
    Keep the default settings and when setting your class paths follow the same path settings.
    eve

  • Runtime exec fail()

    I exec() an shell script, which is not executable. I would like to know how can I handle the exception. I would like to use the getErrorStream() when there is an error. I do not know how do I set it up?
    Thanks

    From the Runtime.exec documentation:
    Starting an operating system process is highly system-dependent. Among the many things that can go wrong are:
    The operating system program file was not found.
    Access to the program file was denied.
    The working directory does not exist.
    In such cases an exception will be thrown. The exact nature of the exception is system-dependent, but it will always be a subclass of IOException.
    Catch and handle the exception. Follow the methods in this tutorial:
    http://java.sun.com/docs/books/tutorial/essential/exceptions/index.html

  • Using Runtime exec() method to run java files and return runtime errors

    Hi
    I'm writing a java editor and I use
    Runtime.getRuntime().exec(command)
    to compile the java files. That works fine and I deal with the returned errors using the getErrorStream().
    My questions are:
    1. Can I use the same technique for returning runtime errors. In any posts I've read the process runs from begining to end, returning the errors after completion. How do I return the errors of the app as they happen interactively?
    2. If i cant use the exec and getErrorStream() methods then does anyone know how it is done?
    Thanks in advance for any help!

    Read this:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
    MOD

  • Runtime.exec fails to launch C++ application

    A java application launches a C++ Windows based application, providing it with arguments on the command line. This application is supposed to start, to execute something and to exit.
    This is working as long as the java code runs from the command prompt.
    When the java code is running as part of a Java Windows 2000 service, the C++ application starts but enters a loop and never returns. It consumes all CPU and waits for something that I could not figure out. I can just see the process in the Task Manager.
    Windows 2000 service is configured as loging on a user account.
    I have not the code of the C++ application and cannot modify it.
    Here is the piece of code that starts this C++ Application :
    //Start the command and wait for completion
    try{
    java.lang.Process submitProcess = Runtime.getRuntime().exec(command);
    submitProcess.waitFor();
    if(submitProcess.exitValue() == 0){
    return;
    } else{
    System.out.println("exitValue = " + submitProcess.exitValue());
    } catch(Exception e){e.printStackTrace();

    For information, wrapping input and error streams did not return any information.
    Doing further testing, I found that this application - a viewer that I use for its command line print functionality- starts looping when I pass as argument a DWG file. If I ask it to print .DOC or .XLS or .HTML ... files, it works.
    If I start the application from Java code at command prompt, it works even with this DWG file and it does not ask for anything.
    My conclusion is that the loop comes from a component used for Autocad conversion when the Java code launching the application is started as Windows 2000 service.

  • Stop Running Programs with Java

    Does anyone know how to stop a non-Java program that is currently running on a PC?

    Hi,
    did you started the programm from your java app with proc = Runtime.getRuntime.exec()?
    If yes, you can kill it with
    proc.destroy()If not, there is no platform-independent way to do it.
    Best regards,
    Martin

  • ER unable to compile using javac with java 1.3.1 library (JDEV 10.1.3.0.4)

    Hi !
    When I try to compile in JDev with javac and the java 1.3.1 library, I get the following error :
    Error: javac: invalid flag: -source
    The command line generated by JDev looks like :
    C:\jdk1.3.1_03\bin\javac.exe -J-mx512m -verbose -deprecation -source 1.3 -target 1.3 -encoding Cp1252 -g -classpath [...] -sourcepath [...] -d [...] @C:\DOCUME~1\user\LOCALS~1\Temp\javac54193.tmp
    It seems that -source and -target flags do not exist in this version of javac.
    But it does not seem possible to remove these flags generated by JDev, so I'm unable to compile with javac 1.3.1 and JDev.
    So i'm looking for :
    - A workaround to prevent JDev from adding the -source and -target flags.
    - A future release of JDev where you could disable these flags, or, much better, where JDev automatically disables these flags when it detects a 1.3.1 library (there may be other incompatible flags I did not mention).
    Thank you for your answers :)

    Hi,
    when you open the project properties and choose the compiler option to tht the compiler to "javac" and then the "source" and "target" to 1.3, wouldn't this compile it for Java 3? I don't think that it is necesary to use JDK 1.3 for compiling the sources
    Cross-Compilation Options
    By default, classes are compiled against the bootstrap and extension classes of the platform that javac shipped with. But javac also supports cross-compiling, where classes are compiled against a bootstrap and extension classes of a different Java platform implementation. It is important to use -bootclasspath and -extdirs when cross-compiling; see Cross-Compilation Example below.
    -target version
    Generate class files that will work on VMs with the specified version. The default is to generate class files to be compatible with the 1.2 VM in the Java 2 SDK. The versions supported by javac in the Java 2 SDK are:
    1.1
    Ensure that generated class files will be compatible with 1.1 and VMs in the Java 2 SDK.
    1.2
    Generate class files that will run on VMs in the Java 2 SDK, v 1.2 and later, but will not run on 1.1 VMs. This is the default.
    1.3
    Generate class files that will run on VMs in the Java 2 SDK, v 1.3 and later, but will not run on 1.1 or 1.2 VMs.
    1.4
    Generate class files that are compatible only with 1.4 VMs.
    http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/javac.html
    Frank

  • Oracle 9.2.0.2 fails open read only with java exception

    Hi folks!
    I hope you can help me to narrow down this issue.
    I've a database running on windows 2003 64 bits. Oracle version is 9.2.0.2.
    I'm experiencing the following issue:
    When I try to open my database in read only mode, it crashes with ORA-604 and ORA-16000.
    The trace is pointing me to some kind of connection to an SQL Server...., but, to tell truth, I'm not understandig the problem, can anyone help me?
    The error itself is:
    java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]No ResultSet set was produced.
    Thanks!

    I know this is not an tail -f 50 ...., but the last 100 lines are equals to the following:
    "starting up 1 shared server(s) ...
    starting up 1 dispatcher(s) for network address '(ADDRESS=(PARTIAL=YES)(PROTOCOL=TCP))'...
    ARCH: STARTING ARCH PROCESSES
    ARC0 started with pid=12
    ARC0: Archival started
    ARC1 started with pid=13
    ARC1: Archival started
    Sun Aug 22 21:36:12 2010
    ARCH: STARTING ARCH PROCESSES COMPLETE
    Sun Aug 22 21:36:12 2010
    ARC0: Thread not mounted
    Sun Aug 22 21:36:12 2010
    ARC1: Thread not mounted
    Sun Aug 22 21:36:13 2010
    ALTER DATABASE MOUNT
    Sun Aug 22 21:36:17 2010
    Successful mount of redo thread 1, with mount id 1255534413.
    Sun Aug 22 21:36:17 2010
    Database mounted in Exclusive Mode.
    Completed: ALTER DATABASE MOUNT
    Sun Aug 22 21:36:32 2010
    alter database open read only
    Sun Aug 22 21:36:34 2010
    SMON: enabling cache recovery
    Sun Aug 22 21:36:34 2010
    Database Characterset is WE8ISO8859P1
    Sun Aug 22 21:36:37 2010
    Errors in file c:\oracle\admin\orcl\udump\orcl_ora_32704.trc:
    ORA-00604: error occurred at recursive SQL level 1
    ORA-16000: database open for read-only access"
    Obviously, with the details of the startup.
    One additional detail:
    After that errors, I started the database on restrict mode, and it opens (I fact, this is not surprising, I was expecting that result)
    I'll keep working on this....

  • OBIEE 11.1.1.5 Config Run Enup with Java Error

    I have sucessfully installed the OBIEE 11.1.1.5 , but unable to run the config.bat file. It end ups with the 'Could not create the java virtual machine'.
    Please help me out.

    Hi,
    We are getting the same issue.
    Did you get it resolved?
    Thanks.
    In hs_err_pid4076.log, I found this.
    Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
    j com.hyperion.hfm.config.EPMWindowsConfigJNI.SetDCOMIdentity(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)I+0
    j com.hyperion.hfm.config.hfmregistry.HFMRegistry.configureHFMDCOMUserInfo(Ljava/lang/String;Ljava/lang/String;)I+654
    j com.hyperion.hfm.config.HfmDComTaskProcessor.execute()V+156
    j com.hyperion.cis.CustomTaskProcessor.execute(Loracle/as/config/impl/HITPortTracker;)V+1
    j com.hyperion.config.wizard.impl.RunAllTasks.executeCustomTask(Lcom/hyperion/cis/CustomTaskProcessor;Lcom/hyperion/cis/config/ProductDescriptor;Ljava/lang/String;Ljava/lang/String;)V+115
    j com.hyperion.config.wizard.impl.RunAllTasks.execute(Lcom/hyperion/config/wizard/SummaryField;Lcom/hyperion/hit/wizard/ProgressComponent;)V+3585
    j com.hyperion.config.wizard.impl.RunnAllTasksState.run()V+69
    j java.lang.Thread.run()V+11
    v ~StubRoutines::call_stub

Maybe you are looking for

  • Is Premier Elements 12 working on Mac OS 10.9.2?

    I am a professional editor.  My job provides me with a AVID MEDIA COMPOSER.  At home I have a 2008 imac in which I used FCP 6.  Since I upgraded to Maverick, the program is not opening.  The problem, I need to edit a project ASAP.  I am contemplating

  • Converting to PDF: Page Size varies

    I have to turn a spreadsheet in to a report. Numbers is doing the business until I export to PDF. One page is not coming out as A4 even though I have set it to be A4, reduced font size, dragged the custom size slider etc it still comes out the way it

  • Report always shows default variant

    Hello, I've got a report where we can choose a variant in the selection screen. SELECTION-SCREEN BEGIN OF BLOCK SEL2 WITH FRAME TITLE TEXT-002. PARAMETERS p_layout TYPE slis_vari. SELECTION-SCREEN END OF BLOCK SEL2. I've got it setup so that when the

  • Iphone 4 IOS 7 charging problem Please read, very stressed.

    Hey all, my Iphone 4 is acting really worrying after the update, my phone isn't charging. If it dies completely, I can plug it in and it will charge enough just to reach about 2,3% and then it will stop completely. However the two nights ago, I left

  • Collective order  - CO1F

    Hi good afternoon! I have a problem in the production record in transaction CO1F (used for collective order). The system is too slow to make the appointment, can someone help me to improve performance? Thank you,