[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] [babel] Parse another code block's output then use captured data
From: |
Andreas Leha |
Subject: |
Re: [O] [babel] Parse another code block's output then use captured data in another code block |
Date: |
Fri, 07 Mar 2014 16:38:07 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) |
Hi Rehan,
Rehan Iftikhar <address@hidden> writes:
> Hello
>
> I have a .org file where I am using sh code blocks to interact with a
> REST API via curl. My first call is to authenticate with the REST API
> which returns a token in the HTTP response. I would like to parse that
> HTTP response (ie. with elisp via a subsequent code block) and use the
> token in subsequent sh code blocks.
>
> Right now I am doing this via a manual step where I step where I run
> the first sh code block, set a :var PROPERTY, and then run the rest of
> the sh code blocks. I would like to automate it if possible.
>
> Thanks,
> -Rehan
I am not sure, if I understand your question correctly. But passing the
token to another code block is easy.
There are two straight forwards ways:
1. As a variable
--8<---------------cut here---------------start------------->8---
#+name: authenticate
#+begin_src sh
## do sth to generate a token
token="uagpb"
echo "$token"
#+end_src
#+name: usethetoken
#+header: :var token=authenticate()
#+begin_src sh
echo "${token}.ext"
#+end_src
#+results: usethetoken
: uagpb.ext
--8<---------------cut here---------------end--------------->8---
2. Using noweb
--8<---------------cut here---------------start------------->8---
#+name: authenticate
#+begin_src sh
## do sth to generate a token
token="uagpb"
echo "$token"
#+end_src
#+name: usethetokenvianoweb
#+begin_src sh :noweb yes
token=<<authenticate()>>
echo "${token}.ext"
#+end_src
#+results: usethetokenvianoweb
: uagpb.ext
--8<---------------cut here---------------end--------------->8---
HTH,
Andreas