The command I'm trying to duplicate:

curl https://example.com | readability https://example.com

As far as I can see, though, using that | pipe is NOT the same as passing the string in as an arg. If I have a string that I am ready to pass to readability, how may I do it in a manner with parity of the bash pipe?


2 Answers 2


See shell-command-on-region (suggestively bound to M-|). You can select a region and call shell-command-on-region, specifying the readability command. The region becomes the standard input for the command.

To pass a string, you can create a temp buffer and insert the string, then set the region to the whole buffer before doing the above. This is done often enough in emacs to make it into an idiom: it's a common technique.


Correct. In a shell like Bash, the pipe character | forwards the output of the command on the left into the input of the command on the right. Whatever the first command prints to file descriptor 1 (which is called the “standard output”) is available for the second command to read from file descriptor 0 (the “standard input”). There are at least two ways to emulate this:

The first is to call start-process to start the second command asynchronously. The return value is a process object that you will need for the next step. Next, call make-process to run the first command. Use the :filter argument to specify a function that will send all output to the second command using process-send-string. Something like this, perhaps:

(let (proc2 (start-process "readability" nil "readability" url))
  (make-process :name "curl"
                :buffer nil
                :command (list "curl" url)
                :filter (lambda (proc output)
                          (process-send-string proc2 output))))

Another option would be to use the command start-process-shell-command, which gives your command to a shell rather than executing it directly. You should be able to give it your pipeline directly, though I’ve never done that before. This option is preferable because it is simpler to write and to understand, though it may be less flexible. On the other hand, quoting things correctly for the shell can be annoying and cumbersome: Something like this:

(start-process-shell-command "readability" "readability"
                             (concat "curl "
                                     (shell-quote-argument url)
                                     " | "
                                     "readability "
                                     (shell-quote-argument url)))

You should also search the packages on ELPA to see if there is anything that lets you create pipelines using a nicer syntax.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.