[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Control of fan-speed on Lenovo Thinkpads
From: |
Jean Louis |
Subject: |
Re: Control of fan-speed on Lenovo Thinkpads |
Date: |
Tue, 30 Mar 2021 23:06:34 +0300 |
User-agent: |
Mutt/2.0.6 (2021-03-06) |
* Stefan Monnier <monnier@iro.umontreal.ca> [2021-03-30 18:03]:
> > (defun sudo (&rest arguments)
> > "Executes list ARGUMENTS with system command `sudo'."
> > (let ((default-directory "/sudo::"))
> > (shell-command-to-string (string-join arguments " "))))
>
> Please don't `string-join` arguments and please don't use a shell when
> it's not necessary: they're recipes for quoting bugs.
> Better use something like `file-process` here.
Yes, you are right, that it works well is coincidence. I think that
string-join came from earlier command which used call-process or
similar where arguments are separate.
I have improved my command, and it still works well.
(defun sudo (command)
"Execute COMMAND with system command `sudo'."
(let ((not-remote (not (file-remote-p default-directory))))
(if not-remote
(let* ((command (format "sudo su -c -- root -c \"%s\"" command))
(return (shell-command-to-string command)))
return)
(message "This `sudo' does not work on remote directory: %s"
default-directory))))
You probably mean process-file? There is no file-process.
There is practical burden to use call-process, and it is with &rest
ARGS, as those have to be given all separately.
One echo to file and command with sudo becomes very complex, and it does not
work:
(call-process "/usr/bin/sudo" nil (get-buffer-create "sudo") nil "su" "-c" "--"
"root" "-c" "echo" "level" "full-speed" ">" "/proc/acpi/ibm/fan")
(call-process "/usr/bin/sudo" nil (get-buffer-create "sudo") nil "su" "-c" "--"
"root" "-c" "echo" "hello" ">" "/tmp/text.txt") → 0 -- but does not produce
/tmp/text.txt, so I do not know how to use it.
Then again I would like to pass a command, and not quote each part of command
as arguments.
I would like something like (sudo "echo hello > /proc/file") that it works.
But for that to work, how I understand, I need to split string with spaces,
remove empty strings maybe, and then pass it as list as ARGS to call-process.
(setq args '("su" "-c" "--" "root" "-c" "echo" "level" "full-speed" ">"
"/proc/acpi/ibm/fan"))
(call-process "sudo" nil t t args) -> this will not work, so to
pass it as a list there, I would need to make a macro expansion?
`(call-process "sudo" nil (get-buffer-create "sudo") nil ,@args) →
(call-process "sudo" nil (get-buffer-create "sudo") nil "su" "-c" "--" "root"
"-c" "echo" "level" "full-speed" ">" "/proc/acpi/ibm/fan")
(defun sudo (command)
"Execute COMMAND with system command `sudo'."
(let ((not-remote (not (file-remote-p default-directory))))
(if not-remote
(let* ((sudo "sudo")
(args (append '("su" "-c" "--" "root" "-c") (split-string
command)))
(status `(call-process ,sudo nil (get-buffer-create "*sudo*") t
,@args)))
(message "%s" status)
(eval status)))))
By using that above function, this will work: (sudo "ls") but this will not
work:
(sudo "ls /boot /var") -- so I do not know how to expand the list properly in
the function.
I would like to get following to work in simpler way by providing string:
(sudo "echo level full-speed > /proc/acpi/ibm/fan")
--
Jean
Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns
- Re: Control of fan-speed on Lenovo Thinkpads, (continued)
- Re: Control of fan-speed on Lenovo Thinkpads, Jean Louis, 2021/03/30
- Re: Control of fan-speed on Lenovo Thinkpads, Michael Albinus, 2021/03/30
- Finding simpler better sudo for Emacs, Jean Louis, 2021/03/30
- Re: Finding simpler better sudo for Emacs, Michael Albinus, 2021/03/30
- Re: Finding simpler better sudo for Emacs, Jean Louis, 2021/03/30
- Re: Finding simpler better sudo for Emacs, Michael Albinus, 2021/03/30
- Re: Finding simpler better sudo for Emacs, Jean Louis, 2021/03/30
- Re: Finding simpler better sudo for Emacs, Michael Albinus, 2021/03/30
- Re: Finding simpler better sudo for Emacs, Jean Louis, 2021/03/30
Re: Control of fan-speed on Lenovo Thinkpads, Stefan Monnier, 2021/03/30
- Re: Control of fan-speed on Lenovo Thinkpads,
Jean Louis <=
- Re: Control of fan-speed on Lenovo Thinkpads, Stefan Monnier, 2021/03/30
- Re: Control of fan-speed on Lenovo Thinkpads, Jean Louis, 2021/03/31
- Re: Control of fan-speed on Lenovo Thinkpads, Stefan Monnier, 2021/03/31
- Re: Control of fan-speed on Lenovo Thinkpads, Jean Louis, 2021/03/31
- Re: Control of fan-speed on Lenovo Thinkpads, Stefan Monnier, 2021/03/31
Re: Control of fan-speed on Lenovo Thinkpads, Utkarsh Singh, 2021/03/31