From: Andreas Leha <andreas.leha@med.uni-goettingen.de>
To: emacs-orgmode@gnu.org
Subject: Re: [babel] Parse another code block's output then use captured data in another code block
Date: Fri, 07 Mar 2014 16:38:07 +0100 [thread overview]
Message-ID: <87pplydnog.fsf@med.uni-goettingen.de> (raw)
In-Reply-To: CAJsxe3OU-Vws+02qaC0GagByiiTMGw9SwYdh00cnNYd+LO6Y2Q@mail.gmail.com
Hi Rehan,
Rehan Iftikhar <rehan.iftikhar@gmail.com> 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
prev parent reply other threads:[~2014-03-07 15:38 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-07 15:23 [babel] Parse another code block's output then use captured data in another code block Rehan Iftikhar
2014-03-07 15:35 ` Eric Schulte
2014-03-07 15:38 ` Andreas Leha [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87pplydnog.fsf@med.uni-goettingen.de \
--to=andreas.leha@med.uni-goettingen.de \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).