emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Eric Schulte <schulte.eric@gmail.com>
To: Rehan Iftikhar <rehan.iftikhar@gmail.com>
Cc: 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 08:35:30 -0700	[thread overview]
Message-ID: <87mwh2qawt.fsf@gmail.com> (raw)
In-Reply-To: <CAJsxe3OU-Vws+02qaC0GagByiiTMGw9SwYdh00cnNYd+LO6Y2Q@mail.gmail.com> (Rehan Iftikhar's message of "Fri, 7 Mar 2014 07:23:43 -0800")

Would something like the following work?

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.

#+name: downloader
#+begin_src sh
  curl something
#+end_src

> 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)

#+name: parser
#+begin_src emacs-lisp :var input=foo
;; do parsing
#+end_src

> and use the token in subsequent sh code blocks.
>

#+begin_src sh :var data=parser(downloader)
echo "$data"
#+end_src

>
> 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.
>

It is possible to chain code blocks in variable lines as shown, see the
manual pages on the :var and potentially also the :post header
arguments.  Also, the following has multiple examples demonstrating this
sort of usage.

http://www.jstatsoft.org/v46/i03/

Best,

>
> Thanks,
> -Rehan

-- 
Eric Schulte
https://cs.unm.edu/~eschulte
PGP: 0x614CA05D

  reply	other threads:[~2014-03-07 15:37 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 [this message]
2014-03-07 15:38 ` Andreas Leha

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=87mwh2qawt.fsf@gmail.com \
    --to=schulte.eric@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=rehan.iftikhar@gmail.com \
    /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).