ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Conor MacNeill" <>
Subject Re: Possible bug - Problem with exec and dir attribute
Date Tue, 30 Jan 2001 15:25:09 GMT

I am attaching a report I submitted to Sun about this problem and their
reply. The short answer is that you need to give the full path to your
executable or have it in your PATH for the exec to work


Hi Conor MacNeill,

The evaluation of your bug report has been completed.

The problem you encountered is not a bug, and the output
is the expected behavior of runtime.exec.

If you have further question about this issue, please let us know.

Thank you for taking the time to report this problem.

----------------- Original Bug Report-------------------

category : java
subcategory : classes_lang
release : 1.3
type : bug
synopsis : runtime.exec is inconsistent when passing a working directory
description : java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)

Runtime.exec is a little inconsistent in how it finds the given executable
command, when provided a working directory. Consider the following setup:
A current directory with a batch file, super.bat
A subdirectory, subdir with a batch file sub.bat

If I execute, through Runtime.exec, super.bat with either a null working
directory or a directory of ".", it functions fine. If I try to execute
in subdir, however, it fails without an exception. Strangely, if I try to
execute super.bat in subdir, it fails in a different way and without an
exception. Finally, passing the full path to sub.bat and executing in

The following Java code illustrates this behaviour (you will need to create
batch files as appropriate):


public class Test {
    public static final void main( String[] args ) {
        execCommand("super.bat", null);
        execCommand("super.bat", new File("."));
        execCommand("sub.bat", new File("subdir"));
        execCommand("super.bat", new File("subdir"));

        File subbatFile = new File("subdir/sub.bat");
        execCommand(subbatFile.getAbsolutePath(), new File("subdir"));

    static private void execCommand(String command, File dir) {
        System.out.println("Executing " + command + " in " + dir);
        Runtime runtime = Runtime.getRuntime();
        byte[] buffer = new byte[2048];
        try {
            Process process = runtime.exec(new String[] {command},
                                           new String[0], dir);
            InputStream is = process.getInputStream();
            int bytesRead;
            while ((bytesRead = != -1) {
                System.out.write(buffer, 0, bytesRead);
            System.out.println("++++++++  Standard Error  ++++++++++");
            is = process.getErrorStream();
            while ((bytesRead = != -1) {
                System.out.write(buffer, 0, bytesRead);
        catch (Exception e) {
workaround : The command to be executed should either be specified exactly,
or exist on the
user's path. In the end, if this doesn't work, it shouldn't work for all
scenarios where the full path is not specified.
suggested_val :
dateCreated : 2001-01-17 05:17:26.6
dateEvaluated : 2001-01-17 10:03:04.898

----- Original Message -----
From: "Michaël Smith" <>
To: <>
Sent: Wednesday, January 31, 2001 12:37 AM
Subject: Possible bug - Problem with exec and dir attribute

> I'm trying to execute a batch file with the following:
>         <exec dir="../../common/common/build" executable="test.bat"
> os="Windows 2000"/>
> I'm noticing some very weird behavior.  It fails unless I have a file
> test.bat in my current directory.  When I have the test.bat locally, the
> build succeeds and does in fact run the correct batch file (I changed
> to echo different messages so I could verify which one is run).  When I
> rename the test.bat that is in my local directory then the build stops
> working.  I reproduced this with several different batch files so I'm
> it's not a coincidence.
> Very strange.  I'm using the latest build, Jan 22.  Has anyone else seen
> this problem?
> Thanks,
> Michaël
> _________________________________________________________________________
> Get Your Private, Free E-mail from MSN Hotmail at

View raw message