Questions tagged [shell-command]
is for executing shell commands from Emacs (the default key binding is `M-!`). Shell output is shown in the echo area if it fits, in buffer `*Shell Command Output*` otherwise. Emacs comes with many supporting facilities for executing shell commands, including interactive execution, selective execution on a region, history cycling, directory tracking, connecting to serial ports, emulator options, and specifying remote hosts.
109
questions
4
votes
1answer
227 views
How to make “shell-command-on-region” display output as a message on a non-zero exit code?
I'd like to replace my selection with the output of a program, an annoyance is - when there is an error, the error replaces my text.
Is there a way to check the exit code and only replace the text if ...
1
vote
2answers
262 views
How to evaluate the selection through Python and replace the selection with it's result?
Being more familiar with Python then elisp, I'd like to evaluate the selection as as Python snipped - as a short-cut to opening a calculator or Python prompt and copy-pasting between them.
Is there a ...
0
votes
1answer
116 views
How to paste to another app from a shell script
I've been getting very vexed by the following.
Goal: Take the clipboard contents and paste them into another application by using a shell script called by Emacs, followed by a Return. [This is for ...
4
votes
2answers
1k views
Using `emacsclient` as `git config core.editor` and invoking `git commit` as `shell-command` in Emacs?
I am trying to use Emacs 25.1.1 (graphical version, Windows 10) as both the primary editor and the editor for git operations.
In my workflow, I invoke git through M-x shell-command.
I tried the ...
1
vote
0answers
106 views
Problem execution scope org-babel in shell on windows 8
I just discovered that in order to run a sequence of shell commands under the same scope (same shell session) I have to add a hash at the end of the line.
Example
When I try to run the following ...
4
votes
1answer
215 views
Refresh `async-shell-command` buffer
When I run a command with async-shell-command, sometimes I would like to quickly rerun the command. I can do this by running async-shell-command again and using M-p to cycle backward through history, ...
1
vote
1answer
131 views
filter log output to Emacs buffer
I want to write a elisp script to filter a log command to output specific logs only.
The log command will never exist till user press 'C-q'.
The log output will be filtered by regex such as "test.*".
...
1
vote
1answer
959 views
How to execute a command on the selection (shell-command-on-region) in evil mode, without losing the selection?
I'd like to use shell-command-on-region on the region, in a way that keeps the selection, even in the case the length of the output changes, and works in regular emacs and in evil mode?
Note, I've ...
1
vote
1answer
133 views
Execute shell command and then some text into document
I have a python script ss.py that gets a screenshot from a connected device and puts into particular dir. From terminal I run it with the target path as an arg:
$ python ss.py {document-name}/{image-...
1
vote
1answer
432 views
Async shell command can't find command
I have installed the Rust programming language (Debian). Now i can compile and run programs from terminal (with the cargo build and cargo run commands), but not from inside emacs. The cargo compiler ...
2
votes
4answers
835 views
Command to Run (Eval) “Hello World” in ELISP on Eshell?
I am new to Emacs and ELISP
A file (message "Hello World") saved as hello.el.
Now, how to run (evaluate) this file on Eshell?
~/Documents $ ....... hello.el
0
votes
1answer
273 views
Shell's “read” command in an elisp script
How can I get the shell's read command working (prompting for the input) in an elisp script? I have
(shell-command "read -s-p \"Enter Password: \" PASSWORD")
but it doesn't prompt anything.
4
votes
1answer
339 views
How to mix eshell and elisp code
If I'm in eshell I can run elisp commands cause I'm in an elisp runtime
(mapcar (lambda (x) (* x 3)) (list 1 2 3))
(3 6 9)
I can also run "shell" commands such as git status. But what if I wanted to ...
0
votes
1answer
624 views
C++ “std::cin >> ” is not pausing to read input from Emacs shell
The following program is from https://www.cs.bu.edu/teaching/tool/emacs/programming/
#include <iostream>
int main()
{
int howmany;
std::cout << "Enter a number: ";
std::cin >&...
2
votes
1answer
532 views
How to open system's command line at the directory of the current buffer?
Is there any easy way to open the system command line interface (e.g., cmd in Windows) at the directory containing the current buffer (if any)? Note that M-x shell open a command line interface within ...
3
votes
1answer
86 views
Show top of *Async Shell Command* buffer
Is there a way to get to the top of a buffer that is not necessarily active?
What I want to do is run a shell command on the word at point and then show the top of the output in the *Async Shell ...
7
votes
4answers
4k views
Get output of external command in the buffer
How do I get the output of (shell-command "df") (or some other more complex command, that I don't want to retype often) in the current buffer?
I run it by typing C-c p after it, but then it opens ...
0
votes
1answer
336 views
How to use an external command to modify selected words and lines?
Something I've found useful in other editors is the ability to:
take the selected text
run an external command and pass the selection to its stdin
take the external commands stdout and replace the ...
3
votes
0answers
299 views
Shutting down computer from emacs killing gracefully emacs itself
I am using EXWM on Arch as my windows manager. Substantially my startx launches
exec dbus-launch --exit-with-session emacs so I am running only emacs and living inside it. I would like to define a ...
3
votes
1answer
1k views
How to run sudo commands using shell-command?
When I run any sudo command using shell-commandāfor example, (shell-command "sudo ls")āI get the following error:
sudo: no tty present and no askpass program specified
How can I get around this? I'm ...
5
votes
1answer
7k views
How do i change the default shell for shell-command
I am having an issue with one of the plugins i am running because its trying to use fish and does not like the parameters.
Is there a way i can change emacs to use bash for any plugins that use shell-...
1
vote
1answer
233 views
interactive shell and C compilation inside emacs
I compiled a simple program in C (it does the sum of 2 numbers), by doing :
M-x compile RET
gcc -dummy.c -o dummy
M-x shell RET
./dummy
I get a prompt for the first number I can enter, then nothing ...
1
vote
1answer
81 views
Is there a package to send a piece of text to shell and get the result back?
I want to know if there is a package to send a piece of text to shell commands like sed, awk or other text processing utilities and then get the result back to emacs? Thanks.
1
vote
1answer
2k views
shell strange characters
When running M-x shell I get strange additional characters.
It looks like this,
I should look similar to how it does in the terminal,
I am very new to Emacs. Hopefully there is a simple fix.
I am ...
1
vote
1answer
347 views
Run a command with C-c C-c for a specific major mode
I have a file with a .md extension, and I want to run a command to interpret/parse a file when markdown-mode is active with a C-c C-c key combination, for example. I want to run this shell command:
...
3
votes
1answer
843 views
Run elisp from command line in running emacs
How can I execute elisp in the currently running emacs from the command line?
The following command echoes 'hi' but doesn't set 'abc in the emacs instance.
emacsclient --no-wait --eval '(message "hi"...
0
votes
2answers
180 views
evaluate sh source code, output is not displayed well
When I evaluate this:
#+begin_src sh
brew list
#+end_src
The result is good:
However, if I use:
#+begin_src sh
brew info emacs
#+end_src
I get something weird:
Does anyone know why this happens?
3
votes
1answer
225 views
Define the window location of the output of shell command
I use M-! to run the command shell-command. The output will open the buffer in a new window at the bottom. Can I configure it to appear on the right?
4
votes
2answers
1k views
Why is there a newline in the result of `shell-command-to-string`?
It seems that emacs appends a newline to the return value for shell-command-to-string. For example, the return value for (shell-command-to-string "pwd") is:
"/path/to/directory
"
While the return ...
0
votes
1answer
36 views
Unexpected behavior when defining variable [duplicate]
I am trying to get the string value of a variable defined in a Python file and assign it to an elisp variable. The value is held in the variable org_file in a file config.py in the same directory as ...
3
votes
1answer
378 views
Set default-directory relative to the place an Elisp function is defined
I have some custom elisp functions that need to run shell scripts using shell-command. I would like to use a relative path to the script, e.g.:
(shell-command "./run.sh")
rather than an absolute one:...
1
vote
0answers
73 views
Display dropbox status
I would like my emacs to call
dropbox status
every 30 seconds and display whether Dropbox is up-to-date at the bottom of the buffer (where info such as the line-number and file name is).
How could ...
2
votes
1answer
3k views
Trying to run a linux program in Emacs: command not found
I have a pdflatex program located in
/usr/local/texlive/2014/bin/i386-linux/pdflatex
I added it's folder to $PATH both in .bashrc and .bash_profile:
PATH=$PATH:/usr/local/texlive/2014/bin/i386-...
5
votes
1answer
552 views
Send input to multiple buffers simultaneously
Is there something like multiple-cursors, but that would send input into multiple buffers at once?
Use case: I want to send the same shell commands to a number of virtual machines and see the output ...
6
votes
1answer
937 views
Key binding with an argument
Say I have a shell command foo that I want to bind to a key. I could do for example:
(global-set-key (kbd "C-c f") (lambda () (interactive) (shell-command "foo")))
I would like to be able to pass an ...
2
votes
1answer
639 views
Append shell-command output to named buffer
In my init file I have a function that runs a shell-command everytime I open emacs. I rarely need to look at the out put of this command, so having it pop up in the *Shell Command Output* buffer every ...
1
vote
1answer
127 views
M-x compile and shell-command ignore default-directory
On one computer I use, my emacs will always run commands in my home directory, rather than the directory of the currently open file (i.e. default-directory).
A standalone reproduction is executing ...
3
votes
0answers
539 views
Emacs on Windows: `shell-command` hangs when process wants input
I am using Emacs on Windows 8.
Some processes when run through shell-command will request interactive input, notably commands like git push (which will ask for user name and password). Sometimes I ...
5
votes
1answer
252 views
Output to magit-process
When I run built-in magit commands, they output to the magit-process buffer. How can I do the same with a custom magit command that generates shell output?
3
votes
2answers
868 views
Shell Command with bash script and arguements
I have a bash script which Sweaves .Rnw files into pdf's.
sweave_to_pdf ~/Foo.Rnw
I am wanting to write a emacs function to invoke this script on the current buffer. So far I have this:
(defun ...
6
votes
1answer
2k views
Why Emacs overrides my PATH when it runs bash?
Why do (shell-command-to-string "echo $PATH") and echo $PATH in eshell differ from echo $PATH from ansi-term and gnome terminal in Ubuntu?
Some paths are missing from (shell-command-to-string "echo $...
1
vote
2answers
272 views
What does the (interactive …) form mean?
I want to write a function that will write the output of wc -l <file-name> next to each file in dired mode.
I got to this point:
(defun my-dired-insert-add-wc (beg end)
(save-excursion
(...
1
vote
0answers
46 views
How can I pass an argument (via highlighting) to a shell command while also passing the filename as an argument?
Im attempting to run a perl script on a buffer which will rearrange/edit the contents. I want to highlight a string and let that be my input as well as the buffer or file.
Currently I can come close. ...
2
votes
1answer
127 views
Using replace-regexp with a shell command
I'm trying to format some text that matches a regexp using an external shell command. I've been able to use C-u M-| successfully on a region, but I can't figure out how to do that within replace-...
1
vote
1answer
320 views
Repeat last shell command shortcut
How can you repeat last shell command with a single shortcut (and no y/n prompts)? How to replace this sequence:
C-u C-x s (or equivalent) to save all buffers
M-! for (shell-command COMMAND &...
2
votes
2answers
283 views
Make shell-command / async-shell-command respect carriage return?
Say I have a simple perl program:
for my $i (0..10) {
print "$i\r"
}
print "\n"
Now if I run the program through shell-command,
instead of getting a single line with 10, I will see the ...
5
votes
1answer
1k views
Executing commands through shell-command (what is the PATH used)?
If I do:
(getenv "PATH")
I get a list of colon-separated directories, including:
/Users/michaeln/Library/Haskell/bin
If I look at the exec-path variable, I see a list including the same ...
8
votes
2answers
882 views
Applying a timeout on call-process/shell-command?
In some cases, when delegating work to an external process, it's useful to set a timeout on the command to prevent Emacs from hanging indefinitely.
Unfortunately, the following does not work.
(with-...
1
vote
1answer
84 views
Why does shell command output sometimes get inserted into an existing buffer?
If I do a M-! to run a shell command, usually any output will appear in a new, temporary buffer. But sometimes, seemingly at random, the output will instead be inserted directly into the active buffer....
13
votes
3answers
3k views
Persistent shell-command history
When I run shell-command in a new session I do not have access to the history of commands from the last session. How can I have that?