Return-Path: Mailing-List: contact ant-user-help@jakarta.apache.org; run by ezmlm Delivered-To: mailing list ant-user@jakarta.apache.org Received: (qmail 3248 invoked from network); 30 Jan 2001 15:24:00 -0000 Received: from mta04.mail.au.uu.net (HELO mta04.mail.mel.aone.net.au) (203.2.192.84) by h31.sny.collab.net with SMTP; 30 Jan 2001 15:24:00 -0000 Received: from cognetnt ([63.12.2.52]) by mta04.mail.mel.aone.net.au with SMTP id <20010130152359.HIGR3144.mta04.mail.mel.aone.net.au@cognetnt> for ; Wed, 31 Jan 2001 02:23:59 +1100 Message-ID: <020701c08ad0$dea3c7c0$6c170c3f@cognetnt> From: "Conor MacNeill" To: References: Subject: Re: Possible bug - Problem with exec and dir attribute Date: Wed, 31 Jan 2001 02:25:09 +1100 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 X-Spam-Rating: h31.sny.collab.net 1.6.2 0/1000/N 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" 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: > > 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. > >