0

This question is related to the solution nanny provides to the xml beautifying problem on this answer: How to prettify/format an XML buffer?

This works for me on Emacs 24.5 on Windows, but I want to know what does "xmllint --format -" parameter of the shell-command-on-region function mean? Apparently "xmllint --format" does not work and when I run "xmllint --format -" in the Windows shell it waits for my input instead of returning to the command interpreter. I am able to input an xml document data from the console and after pressing Ctrl-z RET get my input beautified back to the console.

I am curious what exactly the role of the trailing dash in the shell command execution string is.

Volodymyr
  • 13
  • 4

3 Answers3

3

This isn't really an Emacs question, and it's not even really a question about command shells. It's a convention adopted by a fair number of command-line programs that take filenames as command-line arguments. When you specify - as the filename, they instead read from stdin (or write to stdout).

db48x
  • 15,741
  • 1
  • 19
  • 23
  • And just to be explicit, `shell-command-on-region` sends the text in the marked region to the specified command via standard input, and therefore the command needs to be told to read from stdin (if that is not already its default behaviour). The command's output on stdout will be read by Emacs and used appropriately. – phils Feb 15 '17 at 21:19
0

A token consisting of a single hyphen character is interpreted as an ordinary non-option argument. By convention, it is used to specify input from or output to the standard input and output streams.

Taken from: https://www.gnu.org/software/libc/manual/html_node/Argument-Syntax.html

In your case, this means that arguments will come from standard input.

wvxvw
  • 11,222
  • 2
  • 30
  • 55
  • I think you meant to say that the input will come from stdin, not the arguments. – jtgd Feb 18 '17 at 05:12
  • @jtgd well, technically, the command expects arguments, which represent files it needs to parse. But the way the arguments are delivered is by means of sending some input to this command. So, both statements are true, they just relate to different aspects of what is going on. – wvxvw Feb 18 '17 at 13:29
0

... what exactly the role of the trailing dash in the shell command execution ...

It's a parameter that stands for STDIN or STDOUT, depending on context.

Emacs User
  • 5,553
  • 18
  • 48