9

I try to pipe the output of one source block to the next source block as standard input. Here an example of what I have so far:

Create stdin data:
#+header: :exports code
#+header: :results output
#+begin_src sh
echo "That goes to the next"
#+end_src

#+name: piped
#+RESULTS:
: That goes to the next 

Use "piped" as stdin:
#+header: :exports results
#+header: :stdin piped
#+header: :results output
#+begin_src sh
VALUE=$(cat)
echo "I got:"
echo "$VALUE"
#+end_src

My problems with this are:

  • I have to manually create the result of the first block by hitting C-c C-c

  • the result must be included in org-buffer (large output not needed otherwise)

  • the result must be named manually

Is there a workaround or better way to do this?

8

Here's a simple way to fix your code by naming the src block instead of results:

#+name: piped
#+header: :exports code
#+header: :results output
#+begin_src sh
echo "That goes to the next"
#+end_src

#+RESULTS:
: That goes to the next 

#+header: :exports results
#+header: :stdin piped
#+header: :results output
#+begin_src sh
VALUE=$(cat)
echo "I got:"
echo "$VALUE"
#+end_src

#+results:
: I got:
: That goes to the next
  • 1
    Very good, thanks, that really helped. – theldoria Jun 28 '16 at 14:37
1

Call a src block from another using "noweb" references (see (info "(org) Noweb reference syntax")):

#+name: input
#+header: :exports code
#+header: :results output
#+begin_src sh
echo "That goes to the next"
#+end_src

#+header: :exports results
#+header: :results output :noweb no-export
#+begin_src sh
VALUE=$(<<input>>)
echo "I got:"
echo "$VALUE"
#+end_src

#+results:
: I got:
: That goes to the next
  • 1
    That is cool, good to know, thanks. Unfortunately the second source code block really has to use stdin. The use of cat in the shell was only a simple example. – theldoria Jun 28 '16 at 14:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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