--- a/run-escript.in
+++ b/run-escript.in
@@ -57,7 +57,7 @@
       cd "$CURDIR"
   else
       # name does not contain / therefore we are using
-      tscriptdir=$(which $0)
+      tscriptdir=$(command -v $0)
       if [ $? -ne 0 ]
       then
           die "Unable to determine script directory!"
@@ -210,7 +210,7 @@
 #
 WITH_VISIT=$(get_buildvar visit)
 if [ "$WITH_VISIT" = "1" ]; then
-    VISIT_BIN=$(which visit 2>/dev/null)
+    VISIT_BIN=$(command -v visit 2>/dev/null)
     if [ $? -eq 0 ]; then
         VISIT_PY_PATH=$($VISIT_BIN -env | grep LIBPATH | cut -d= -f2)
         EXTRA_PYTHONPATH=$EXTRA_PYTHONPATH:$VISIT_PY_PATH
@@ -387,7 +387,7 @@
 
 if [ ! -z "$DO_VALGRIND" ]
 then
-    VALGRIND_BIN=$(which valgrind 2>/dev/null)
+    VALGRIND_BIN=$(command -v valgrind 2>/dev/null)
     if [ $? -eq 0 ]; then
         LOGDIR=$ESCRIPT_ROOT/valgrind_logs
         [ -d $LOGDIR ] || mkdir $LOGDIR
@@ -469,7 +469,7 @@
 
 if [ "$MPI_FLAVOUR" = "OPENMPI" ]
 then
-    if [ -z `which rsh``which ssh` ]
+    if [ -z `command -v rsh``command -v ssh` ]
     then
         AGENTOVERRIDE="--gmca plm_rsh_agent /bin/false"
     fi
--- a/site_scons/dependencies.py
+++ b/site_scons/dependencies.py
@@ -33,6 +33,15 @@
 
 REQUIRED_BOOST = (1, 46)
 
+def which(cmd):
+    hits = []
+    paths = os.environ['PATH'].split(os.pathsep)
+    for path in paths:
+        hit = os.path.join(path, cmd)
+        if os.path.isfile(hit):
+            hits.append(hit)
+    return hits
+
 def CheckComplexAcos(context):
     context.Message('Checking for working complex std::acos()... ')
     result = context.TryRun("""
@@ -750,13 +759,10 @@
             except OSError:
                 pass
         else:
-            which = Popen(['which', 'gmsh'], stdout=PIPE)
-            path,_ = which.communicate()
-            path = path.decode()
-            if which.wait() == 0:
-                cmd = ['ldd', path[:-1]]
-                if env['IS_OSX']:
-                    cmd = ['otool','-L', path[:-1]]
+            path = which('gmsh')
+            cmd = ['ldd', path]
+            if env['IS_OSX']:
+                cmd = ['otool','-L', path]
                 try:
                     p=Popen(cmd, stdout=PIPE)
                     gmshlibs,_ = p.communicate()
