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

monks,

#!/usr/bin/perl system("which ls");
Output :-
machtype: Command not found. /usr/bin/ls
I am unaware of what is machtype in the output. when I did a google I found a linnk which describes about MACHTYPE. But I am getting this error only from the perl script.

Replies are listed 'Best First'.
Re: getting a problem when I use which command with system function
by sgifford (Prior) on Nov 03, 2006 at 06:07 UTC
    Look around in your dotfiles (or the dotfiles of the user running the script), like .profile, .bashrc, .cshrc, etc. I bet one of these is running machtype, and it's not in the path or is an undefined shell function.

    Update: Fixed forrmatting error.

      thanks a lot sgifford.
      #setenv MACH `machtype`
      found in $HOME/.cshrc. I commented this line. after that I got the expected behaviour from my perlscript.

        I actually ran into a problem with 'which' and a '.cshrc' file a week or two ago when doing some shell scripting on MacOS X

        In my case, it was much more subtle, as which was written in csh, but that wasn't the shell I was using. So when it called the .cshrc, it overwrote PATH, and would report programs that weren't in my path when I was using bash.

        (of course, which is a builtin under csh, so the odds of you calling the script under csh in normal use should be non-existant)

        Oddly enough, there's a note about 'DO NOT USE "csh -f"' immediately after the shebang line, which fixes the problem, but I have no idea what other implications it might have.

Re: getting a problem when I use which command with system function
by msk_0984 (Friar) on Nov 03, 2006 at 05:17 UTC
    Hi

    Actually i am not getting any error i am able to get the output perfectly.

    #!/usr/bin/perl print " HELLO \n"; system( " which ls ");

    OUTPUT

    HELLO /bin/ls


    Work Hard Party Harderrr!!
    Sushil Kumar
      Tried it as well:
      # Debian and CentOS Linux: perl -e 'system("which ls");' /bin/ls
      Only on windows it did not work, since i use cygwin to perform most linux like functions...
      U:\>perl -e 'system("which ls");' /usr/bin/ls U:\>/bin/ls The system cannot find the path specified. U:\>
      What os are you using?
      "We all agree on the necessity of compromise. We just can't agree on when it's necessary to compromise." - Larry Wall.