From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: =?ISO-8859-1?Q?Andreas_R=F6hler?= Newsgroups: gmane.emacs.help Subject: Re: system-command-exists-p Date: Mon, 07 Dec 2009 13:02:34 +0100 Message-ID: <4B1CEEDA.1060300@easy-emacs.de> References: <87bpibf5xl.fsf@galatea.local> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1260187970 11959 80.91.229.12 (7 Dec 2009 12:12:50 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 7 Dec 2009 12:12:50 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: "Pascal J. Bourguignon" Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Dec 07 13:12:43 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1NHcSJ-0006xv-32 for geh-help-gnu-emacs@m.gmane.org; Mon, 07 Dec 2009 13:12:43 +0100 Original-Received: from localhost ([127.0.0.1]:41516 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NHcSI-00032k-Jh for geh-help-gnu-emacs@m.gmane.org; Mon, 07 Dec 2009 07:12:42 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NHcJK-0007Fv-7l for help-gnu-emacs@gnu.org; Mon, 07 Dec 2009 07:03:26 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NHcJD-0007AU-W6 for help-gnu-emacs@gnu.org; Mon, 07 Dec 2009 07:03:24 -0500 Original-Received: from [199.232.76.173] (port=41954 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NHcJD-0007A3-MS for help-gnu-emacs@gnu.org; Mon, 07 Dec 2009 07:03:19 -0500 Original-Received: from moutng.kundenserver.de ([212.227.17.8]:50750) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NHcJC-0004eY-LV for help-gnu-emacs@gnu.org; Mon, 07 Dec 2009 07:03:19 -0500 Original-Received: from [192.168.178.27] (p54BEBB0A.dip0.t-ipconnect.de [84.190.187.10]) by mrelayeu.kundenserver.de (node=mrbap2) with ESMTP (Nemesis) id 0MJnBU-1NGVpy2J7M-001JfS; Mon, 07 Dec 2009 13:02:47 +0100 User-Agent: Thunderbird 2.0.0.19 (X11/20081227) In-Reply-To: <87bpibf5xl.fsf@galatea.local> X-Provags-ID: V01U2FsdGVkX19FNmxXtWCsolO4NiywDf0sNMhndG2NKboyuCx P8zU3ZJTU1XOot9cAe06GqPmRs9vN9JRU5BlAI6D0Dpo2yGy9i FdByMticY93SrHciStlCODZ+JIcOI2VN91hQDIhK+U= X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:70470 Archived-At: Pascal J. Bourguignon wrote: > Andreas Roehler writes: > >> Hi, >> >> needed a check if a command exists on system. >> Employed the following: >> >> (defun system-command-exists-p (command) >> "Return t if COMMAND is available on system. " >> (let* ((cmd (format "type %s" command))) >> (eq 0 (shell-command cmd)))) >> >> Any comments/suggestions? > > Use %S or (shell-quote-argument command). > > type is a built-in command specific to the sh familly of shells. > Perhaps it would be a good idea to explicitely call up sh? > > It may be useful to return the path of the command: > > (defun system-command-exists-p (command) > "Return t if COMMAND is available on system. " > (let* ((cmd (format "/bin/sh -c 'type %s'" > (shell-quote-argument command)))) > (when (eql 0 (shell-command cmd)) > (let ((result (shell-command-to-string cmd))) > (if (string-match "^.* is \\(.*\\)\n$"result) > (match-string 1 result) > result))))) > > (mapcar (function system-command-exists-p) > '("cat" "type" "foo")) > --> ("/bin/cat" "a shell builtin" nil) > > > Thanks a lot. Concerning the precise kind-of-"shell"-question, I'm not sure. Case is to write a check for pack-unpack functions. Presently dired-do-compress uses a hard-encoded "gzip", replaced here by a choice so far. Then testing all compressing/uncompressing possibilities, it turns out some might not be installed. type uncompress => uncompress is /usr/bin/uncompress type compress => bash: type: compress: not found Test should not fail, if these programms are not installed, rather give a message. So far the issue here. Think the shell-in-use should not matter, resp. will be selected already. What about to write: (cmd (format (concat (getenv "SHELL") " -c 'type %s'") Thanks again Andreas