ant-user mailing list archives

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

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
sub.bat
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
subdir
works.

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

import java.io.*;

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("------------------------------------");
        System.out.println("Executing " + command + " in " + dir);
        System.out.println("------------------------------------");
        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 = is.read(buffer)) != -1) {
                System.out.write(buffer, 0, bytesRead);
            }
            System.out.println("++++++++  Standard Error  ++++++++++");
            is = process.getErrorStream();
            while ((bytesRead = is.read(buffer)) != -1) {
                System.out.write(buffer, 0, bytesRead);
            }
        }
        catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("====================================");
    }
}
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" <news_michael@hotmail.com>
To: <ant-user@jakarta.apache.org>
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
them
> 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
sure
> 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 http://www.hotmail.com.
>
>


Mime
View raw message