help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Control of fan-speed on Lenovo Thinkpads


From: Utkarsh Singh
Subject: Re: Control of fan-speed on Lenovo Thinkpads
Date: Wed, 31 Mar 2021 11:19:54 +0530

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 via email to

[Prev in Thread] Current Thread [Next in Thread]