gri6507 has asked for the wisdom of the Perl Monks concerning the following question:

Fellow monks,

I am trying to find a path to some executable from within my program using my @path = `which myprog`;. Running this on my linux box gives me either the correct path (if found) or which: no myprog in ($PATH).

The same program running under Solaris has a different behavior. Apparently, which for some reason tries to source my $HOME/.cshrc file, which has a problem, and therefore @path has the error message from sourcing .cshrc instead of actual path. How can I bypass this behavior? (ie, don't run backticks interactively).

Update Running any command other than 'which' seems to be NOT sourcing $HOME/.cshrc

Replies are listed 'Best First'.
Re: backticks problem
by adrianh (Chancellor) on Aug 06, 2004 at 19:49 UTC
Re: backticks problem
by blue_cowdawg (Monsignor) on Aug 06, 2004 at 19:50 UTC

        How can I bypass this behavior? (ie, don't run backticks interactively).

    If your .cshrc is being sourced in that seems to mean to me that your $ENV{SHELL} is set to /bin/csh or /bin/tcsh. Have you tried setting it to /bin/sh or some other shell? You could also try using File::Which instead of using the *nix command within backticks.

      Ok, so i tried
      use strict; $ENV{SHELL} = '/bin/bash'; my $i = `which prog`; print "$i\n";

      and I still get the error message from sourcing .cshrc

        Solaris will always check your .cshrc file when running which, regardless of your shell. I'm not sure of any way around this other than fixing your .cshrc file.

        The suggestion to use File::Which is a good one. Relying on a backtick command invariably introduces portability problems, which require a lot of defensive coding to work around (hence the astounding complexity of GNU configure and the like.)