From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Utkarsh Singh Newsgroups: gmane.emacs.help Subject: Re: Control of fan-speed on Lenovo Thinkpads Date: Wed, 31 Mar 2021 11:19:54 +0530 Message-ID: <87pmzfkh31.fsf@gmail.com> References: <8735wcogti.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="3993"; mail-complaints-to="usenet@ciao.gmane.io" To: Jean Louis , help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Wed Mar 31 08:13:31 2021 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lRU6d-0000ue-QU for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 31 Mar 2021 08:13:31 +0200 Original-Received: from localhost ([::1]:58650 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lRU6c-0000jr-ST for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 31 Mar 2021 02:13:30 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:58624) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lRThd-0005BF-MP for help-gnu-emacs@gnu.org; Wed, 31 Mar 2021 01:47:41 -0400 Original-Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]:33766) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lRThc-00031z-4f for help-gnu-emacs@gnu.org; Wed, 31 Mar 2021 01:47:41 -0400 Original-Received: by mail-pl1-x62b.google.com with SMTP id f17so7336036plr.0 for ; Tue, 30 Mar 2021 22:47:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:in-reply-to:references:date:message-id:mime-version :content-transfer-encoding; bh=T9mgjPckbk1B5anGkEOE3Y2SbXjGlfU8UwJiis9fcxo=; b=tOnjVwzfUrkUINCGiG21tsib8wSw70YtOSHzbFDEYFKB0183aGudoXAt2o+N3QnfNP LyKPSrnjC+e8qf77jhS/+IhUVVGX9vXxdWVmDli7wjVh+NTz9Tc9dxqOmGnaGoOvxOdO YSILFfb+jRo11gOrY3G45K6JoIbo2/iZLHXmjEdvaZufiGSItzRaXfGzbM+sSua6RcC/ K0/jQvEWT+nZWnkJQDIJdh9jrnjHvwiG2M1z+pNiTPeTWPM5Vy4K1T8KlKUWRTPmrTmv TjgNwImip0F4BjYo4AndoB0sev/ZwjtP4dBBLBjsJyVD243/w4WvP4AOO3IaDcd0IL6e w2pQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:in-reply-to:references:date :message-id:mime-version:content-transfer-encoding; bh=T9mgjPckbk1B5anGkEOE3Y2SbXjGlfU8UwJiis9fcxo=; b=cAGQghVUTTF1fFiDDRa1u/LjC/1oxK3LSY740hqVVJZDQtMIUxrvP2moyvotl5zAQM Ku0+AR3EVHQ9Fn/qCp8TSIh91MsnUWmOVS+Rbb26NFrSoxPgwl3GwQDBfoF8NVYdoiL7 AFmjvkjRBL+6c9nJ1rlUBjn5W+o07q93ZJvMWLFDNtiG14VMYLt9S1WT+OsGL1ETAZTu UA7jaV48Nz/kqPLqzeW/QF2nNCoCBw4HpJtYBMGPYstiQG4SzAR9uNmzSfMzuTbHIRxn vAkP6EstLfBAvBoHrnBAJ6VCQARCditSLEf4OwOJVcQD9IpqB4IRB78j3G6xqjYPzh79 BxFQ== X-Gm-Message-State: AOAM533nR4//rnKQW7IIgsDbyduZcEma1S1BwqU3sAmK6RLtHeEnCF/t 5xXS03Cry5yjRsEGoHRmfJU= X-Google-Smtp-Source: ABdhPJyw0hljj4D83dTRbPsdfqNFq8QisSRehqF5fLSF/oRZrLG/VSPxmIek7WKsqZk6XBCCJtNGOg== X-Received: by 2002:a17:90a:174c:: with SMTP id 12mr1825488pjm.40.1617169658170; Tue, 30 Mar 2021 22:47:38 -0700 (PDT) Original-Received: from localhost ([45.251.50.159]) by smtp.gmail.com with ESMTPSA id t12sm1030199pga.85.2021.03.30.22.47.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Mar 2021 22:47:37 -0700 (PDT) In-Reply-To: Received-SPF: pass client-ip=2607:f8b0:4864:20::62b; envelope-from=utkarsh190601@gmail.com; helo=mail-pl1-x62b.google.com X-Spam_score_int: 1 X-Spam_score: 0.1 X-Spam_bar: / X-Spam_report: (0.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, PDS_OTHER_BAD_TLD=1.999, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Wed, 31 Mar 2021 02:12:53 -0400 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:128782 Archived-At: Jean Louis writes: > * Utkarsh Singh [2021-03-30 17:28]: >> Hi Jean, >>=20 >> > (defun sudo (arguments) >> > "Executes list ARGUMENTS with system command `sudo'." >> > (let* ((command (format "sudo su -c -- root -c \"%s\"" (string-join = (list=20 >> > arguments)))) >> > (return (shell-command-to-string command))) >> > return)) >>=20 >> Why are you using a separate function for using sudo? > > That way it is distinguished. > >> Why not just have wrapper around call-process function? >>=20 >> Here is my approach (adapted from https://protesilaos.com/dotemacs/): >>=20 > (defun ut-common-shell-command (command &rest args) > "Run COMMAND with ARGS. > Return the exit code and output in a list." > (with-temp-buffer > (list (apply 'call-process command nil (current-buffer) nil args) > (buffer-string)))) > > (ut-common-shell-command "sudo su -c -- root -c \"echo level full-speed >= /proc/acpi/ibm/fan\"") > > apply: Searching for program: No such file or directory, sudo su -c -- > root -c "echo level full-speed > /proc/acpi/ibm/fan" [2 times] > > Well not working how I would like it, I need to dissect it in each > separate comand: > > (ut-common-shell-command "sudo" "su" "-c" "--" "root" "-c" "ls") =E2=86= =92 (0 "0install-ea1f1e-download > 847cf980479cf1dd15482464efa8620ca98c1c93c5a3ac1e2a1dd24918b9cd46.html > adb.1001.log > ") You can use something like this if you don't want to separate thing manuall= y: (let* ((cmd "ls -l -a") (cmd-list (split-string cmd " "))) (apply 'ut-common-shell-command cmd-list)) > > and I am getting lists as output. > > This does not work as it should: > > (ut-common-shell-command "sudo" "su" "-c" "--" "root" "-c" "echo level fu= ll-speed > /proc/acpi/ibm/fan\") > > So you see the problem? > > This works with my function: > > (sudo (format "echo level %s > %s" arg my-fan-proc-file))) > >> I use this by giving "sudo" as first argument. Here is a snippet from >> the library I have written to mount and umount USB and Android devices >> from emacs. >>=20 >> (defun emount-umount-usb (mount-point) >> "Umount usb mounted at MOUNT-POINT." >> (interactive (list (emount--select-umount-usb (emount--get-drive-list = emount--list-drive)))) >> (let* ((result (ut-common-shell-command "sudo" "umount" mount-point)) >> (exit-code (nth 0 result)) >> (output (nth 1 result))) >> (if (eq exit-code emount--success-code) >> (message "%s umount successful" mount-point) >> (user-error output)))) > > That is good. > > You see in this case with redirection of output, it is not so easy to > provide a command with call-process. > Hmm I see the problem with redirection. Do you know any other standard Emacs way to work with redirection? Maybe temp buffer? --=20 Utkarsh Singh utkarshsingh.xyz