From 006b093ab20fd85da0a95dfa967d3eb4d5d26fe7 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Wed, 2 Apr 2003 14:53:22 +0000 Subject: [PATCH] Don't hardcode /usr/bin/env for Unix. PR: 17642 git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274375 13f79535-47bb-0310-9956-ffa450edef68 --- WHATSNEW | 5 +++- .../apache/tools/ant/taskdefs/Execute.java | 26 +++++++++++-------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/WHATSNEW b/WHATSNEW index d7bd00f80..54485a2b8 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -79,6 +79,9 @@ Fixed bugs: * will now recompile your grammar if the supergrammar has changed. Bugzilla Report 12691. +* will now work on Unices with /bin/env instead of + /usr/bin/env. Bugzilla Report 17642. + Other changes: -------------- * Shipped XML parser is now Xerces 2.4.0 @@ -145,7 +148,7 @@ Other changes: * has a new dirmode attribute to specify the permissions for directories. -* 's eol attribute now also understand "mac", "unix" and "dos". +* 's eol attribute now also understands "mac", "unix" and "dos". * now picks up dependencies of the form MyClass.class. This works for the code generated by the Sun java compiler. It may not work for diff --git a/src/main/org/apache/tools/ant/taskdefs/Execute.java b/src/main/org/apache/tools/ant/taskdefs/Execute.java index 8f96009af..ad05a0a61 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Execute.java +++ b/src/main/org/apache/tools/ant/taskdefs/Execute.java @@ -229,19 +229,23 @@ public class Execute { String[] cmd = {"command.com", "/c", "set" }; return cmd; } - } else if (Os.isFamily("z/os")) { - String[] cmd = {"/bin/env"}; - return cmd; - } else if (Os.isFamily("tandem")) { -// String[] cmd = {"/bin/sh -c env"}; - String[] cmd = {"/bin/env"}; - return cmd; - } else if (Os.isFamily("unix")) { - // Generic UNIX - // Alternatively one could use: /bin/sh -c env - String[] cmd = {"/usr/bin/env"}; + } else if (Os.isFamily("z/os") || Os.isFamily("tandem") + || Os.isFamily("unix")) { + // On most systems one could use: /bin/sh -c env + + // Some systems have /bin/env, others /usr/bin/env, just try + String[] cmd = new String[1]; + if (new File("/bin/env").canRead()) { + cmd[0] = "/bin/env"; + } else if (new File("/usr/bin/env").canRead()) { + cmd[0] = "/usr/bin/env"; + } else { + // rely on PATH + cmd[0] = "env"; + } return cmd; } else if (Os.isFamily("netware") || Os.isFamily("os/400")) { + // rely on PATH String[] cmd = {"env"}; return cmd; } else {