all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Utkarsh Singh <utkarsh190601@gmail.com>
To: Jean Louis <bugs@gnu.support>,  help-gnu-emacs@gnu.org
Subject: Re: Control of fan-speed on Lenovo Thinkpads
Date: Wed, 31 Mar 2021 11:19:54 +0530	[thread overview]
Message-ID: <87pmzfkh31.fsf@gmail.com> (raw)
In-Reply-To: <YGNq8IGh12I+QL9I@protected.localdomain>

Jean Louis <bugs@gnu.support> writes:

> * Utkarsh Singh <utkarsh190601@gmail.com> [2021-03-30 17:28]:
>> Hi Jean,
>> 
>> > (defun sudo (arguments)
>> >   "Executes list ARGUMENTS with system command `sudo'."
>> >   (let* ((command (format "sudo su -c -- root -c \"%s\"" (string-join (list 
>> > arguments))))
>> >          (return (shell-command-to-string command)))
>> >     return))
>> 
>> Why are you using a separate function for using sudo?
>
> That way it is distinguished.
>
>> Why not just have wrapper around call-process function?
>> 
>> Here is my approach (adapted from https://protesilaos.com/dotemacs/):
>> 
> (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") → (0 "0install-ea1f1e-download
> 847cf980479cf1dd15482464efa8620ca98c1c93c5a3ac1e2a1dd24918b9cd46.html
> adb.1001.log
> ")
You can use something like this if you don't want to separate thing manually:
(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 full-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.
>> 
>> (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?
-- 
Utkarsh Singh
utkarshsingh.xyz



       reply	other threads:[~2021-03-31  5:49 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <8735wcogti.fsf@gmail.com>
     [not found] ` <YGNq8IGh12I+QL9I@protected.localdomain>
2021-03-31  5:49   ` Utkarsh Singh [this message]
2021-03-31  6:27     ` Finding simpler better sudo for Emacs Jean Louis
2021-03-29 20:36 Control of fan-speed on Lenovo Thinkpads Jean Louis
2021-03-30  8:12 ` Michael Albinus
2021-03-30  9:42   ` Jean Louis
2021-03-30  9:44   ` Jean Louis
2021-03-30 10:13     ` Michael Albinus
2021-03-30 15:01   ` Stefan Monnier
2021-03-30 20:06     ` Jean Louis
2021-03-31  1:23       ` Stefan Monnier
2021-03-31  5:35         ` Jean Louis
2021-03-31 14:23           ` Stefan Monnier
2021-03-31 20:02             ` Jean Louis
2021-03-31 20:19               ` Stefan Monnier
2021-04-01  9:46                 ` Jean Louis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87pmzfkh31.fsf@gmail.com \
    --to=utkarsh190601@gmail.com \
    --cc=bugs@gnu.support \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.