Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

0
votes
2answers
45 views

Multiple async-shell-command commands in sequence

What is the correct way to run multiple async-shell-command invocations serially? For example, this will execute all at once. (progn (async-shell-command "echo 1; sleep 1") (async-shell-command ...
0
votes
1answer
31 views

Sudo caching on compilation mode

There is a command I run very often using compile that must be run as sudo. I wanted to achieve something similar to the 5min caching of sudo in a shell: if I keep running the command in intervals ...
0
votes
2answers
44 views

Split command line into a list of arguments

How do I take a string giving a shell command line such as: "program arg1 arg2 \"long argument with spaces\" arg\\\"3" and turn it into a list of unquoted arguments like: ("program" "arg1" "arg2" "...
0
votes
0answers
43 views

Run custom bash functions with M-!

I have a few custom bash functions that are defined is some file and are made available to me in regular terminals via the line . "/path/Custom Bash Functions.sh" in my ~/.bashrc. However, Emacs ...
0
votes
1answer
30 views

Change async-shell-command with a synchronous command keeping the dynamically displayed buffer

I have this snippet of code: (async-shell-command (concat "perl myscript.pl " (buffer-name)) (read-string "RETURN: ") (with-temp-file "file.new" (insert-file-contents "file.new") (perform-...
0
votes
2answers
51 views

shell command on region with process substitution

If I want to execute a shell command on a region I know I can use shell-command-on-region via M-|, what if the command I want to redirect my selection does not accept redirection to it's standard ...
2
votes
1answer
53 views

Making custom shell command function have popup buffer showing std-out

I'm customizing spacemacs for my workflow. I'm new to elisp and can't figure out how to do this after looking at other functions in .el files and other posts. Basically, I wrote an elisp function ...
0
votes
0answers
38 views

How to remove ^[(B in Emacs-nox shell buffer?

Emacs-nox shell (M-x shell) generate on output of yum search and other type of command a ^[(B ================================================ N/S matched: linker =====================================...
4
votes
1answer
176 views

Run elisp when `async-shell-command` is done

I want to run some Elisp when my command executed by async-shell-command terminates. How can I do this? Does it have completion hooks?
2
votes
1answer
208 views

Differences between cmdproxy.exe and cmd.exe

What is the difference between: (call-process "cmdproxy" nil "foo" nil "/c" "dir") (call-process "cmd" nil "foo" nil "/c" "dir") ? I seem to get exactly the same results in Emacs 25.1 on ...
1
vote
1answer
65 views

Calling shell-command from org-capture-templates to scrape verb conjugations

I want to use org-capture-templates to scrape french verb conjugations from the web and insert them into an org-file to use with org-drill. I have a (functioning) scraper that gets the desired data ...
0
votes
1answer
408 views

Saving to clipboard in a Python script running as shell command

The following python script successfully copies a given string into the clipboard when run from Ubuntu shell: import os text = 'The text to be copied to the clipboard.' os.system("echo -n {s} | xsel -...
9
votes
2answers
124 views

How to run a previous unique command in an Emacs shell (without repeats)?

In Emacs shell, is there a command similar to M-p but which would skip repeated commands? That is, it would go to the next different command. Similar to regular Linux terminal. So if I were to run: ...
5
votes
1answer
83 views

Asynchronous version of shell-command-on-region?

I have a problem which is very similar to this one. I have some text that I'd like to listen to with macOS's say utility. Unfortunately, Emacs locks up when I use shell-command-on-region because it is ...
5
votes
1answer
138 views

xclip hangs shell-command

I like to use the xclip utility to capture the output of commands on the clipboard. However, when I try to use it with shell-command it seems to hang. In a "normal" shell I can run a command such as ...
1
vote
1answer
49 views

is there a shell-command-at-point

This is a bit of a long shot, but I'm going to ask anyway. Kinda similar to what dired-at-point and find-file-at-point When point is inside a .txt file on a line like this ls -la /tmp/ When point ...
1
vote
1answer
95 views

How to improve the `M-! command` output

I found this really cool in emacs M-! t t is ~/bin/t, and runs tests for whatever thing I'm working on. I added ~/bin/ to my /etc/path.d/, and I always use emacs -nw. My issue is, the command ...
0
votes
1answer
79 views

Best way to test output sent to a buffer

I'm writing an emacs package for Pipenv and the spike solution uses sync shell calls, which is not desirable for general usage. I'm now changing calls to be async (make-process) and for output to go ...
0
votes
0answers
71 views

output of detached command in async-shell-command

Let's say I have a script.sh: #!/bin/bash some_command & Then I run: (async-shell-command "script.sh") So far I was not able to see the output of some_command. Is there a way to get it somehow?...
0
votes
1answer
220 views

Git bash opens in window outside of emacs

When running Emacs on Windows 10, I am able to launch git bash from within Emacs using the information given here, here, or here. For example, I can just add these two lines to my .emacs: (setq ...
5
votes
1answer
88 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
104 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
59 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 ...
3
votes
1answer
420 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
46 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 ...
3
votes
1answer
114 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
53 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
473 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
107 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-...
0
votes
1answer
198 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
404 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
166 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.
5
votes
1answer
157 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
319 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
199 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
60 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 ...
4
votes
4answers
937 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
122 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 ...
4
votes
0answers
160 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
469 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 ...
2
votes
1answer
4k 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
134 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
54 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
731 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
279 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: ...
2
votes
1answer
305 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
128 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
169 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?
3
votes
2answers
763 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
25 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 ...