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.

shell-command is an Emacs command that executes a single shell command in a shell. It puts short output in the and long output in buffer *Shell Command Output*.

Tags related to include , , and .

Useful Links:

146 questions
5
votes
2 answers

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 value for (pwd) is "/path/to/directory". In other…
elethan
  • 4,825
  • 3
  • 30
  • 56
5
votes
1 answer

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 directory. If I do: (shell-command "echo $PATH") I…
4
votes
1 answer

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 it's zero.
ideasman42
  • 8,786
  • 1
  • 32
  • 114
4
votes
1 answer

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, but I would prefer to just press g in the output…
Matthew Piziak
  • 6,038
  • 3
  • 31
  • 79
3
votes
1 answer

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-linux/ When I run this command in ordinary shell: both…
user4035
  • 1,059
  • 13
  • 24
3
votes
2 answers

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 sweave_to_pdf () "sweave_to_pdf…
2
votes
2 answers

Run (async-)shell-command in view-mode

How do I run (async-)shell-command (but no other shell-mode buffers) in view-mode?
Mattias Bengtsson
  • 1,300
  • 1
  • 11
  • 18
2
votes
0 answers

Exec a external shell command that have external read input - ex:cookiecutter

As the examble like cookicutter, it have a read input in itself that we must type if we use it in normal terminal. $> #comment: this is normal terminal emulator $> cookiecutter $HOME/cookiecutter/script $> enter script name: $>…
Kidman
  • 31
  • 2
2
votes
1 answer

Emacs shell not picking aliases from bashrc

NOT Working: /bin/bash: Psu: command not found M-! cmd Psu Working M-! cmd ls .bashrc cat ~/.bashrc | grep Psu cat ~/.bashrc | grep aliases alias Psu='sudo pacman -Syyu' if [ -f ~/.bash_aliases ]; then . ~/.bash_aliases .bash_profile cat…
jjk
  • 734
  • 4
  • 18
2
votes
2 answers

Compile and run single file c++ programs in Emacs[SOLVED]

I want to bind to a key a compile-and-run function to be able to compile my C++ single file programs and run them into a term/shell so I could give my variables values whenever I use cin in my programs. For example, in my Neovim config, I had this…
user26482
  • 31
  • 5
2
votes
1 answer

When does shell-command-on-region actually pass the region to the command?

I am having some trouble understanding how shell-command-on-region works. Sometimes the region is passed to command, sometimes not, as far as I can tell. Suppose I have an emacs buffer with "word" in the region, then counting the region's length…
stefano
  • 175
  • 3
1
vote
0 answers

shell-command changing the behavior of my program

Consider the following C code: #include #include int main() { printf("PID: %d\n", getpid()); fork(); } This should output the PID of the process and then fork a clone. When trying from a shell, this behaves in the expected…
rahmu
  • 111
  • 3
1
vote
1 answer

How can I add custom shell command in for my project?

In my project, I write scripts to deploy it to server. Here are the commands: npm run deploy:internal npm run deploy:staging npm run deploy:production I want to add custom shell commands to magit, so that I can press ddi to run npm run…
user2331095
  • 113
  • 3
1
vote
1 answer

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.*". The filtered output print to emacs buffer. How…
beetlej
  • 1,098
  • 1
  • 7
  • 20
1
vote
1 answer

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 running Fedora 25 and GNU Emacs 25.1.1
ofey
  • 111
  • 2
1
2