From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andreas Leha 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 Message-ID: <87pplydnog.fsf@med.uni-goettingen.de> References: Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:52112) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WLwr4-0004Ju-6F for emacs-orgmode@gnu.org; Fri, 07 Mar 2014 10:38:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WLwqt-0004Bk-8T for emacs-orgmode@gnu.org; Fri, 07 Mar 2014 10:38:34 -0500 Received: from plane.gmane.org ([80.91.229.3]:42803) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WLwqs-0004BT-Rl for emacs-orgmode@gnu.org; Fri, 07 Mar 2014 10:38:23 -0500 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1WLwqq-0003kv-GZ for emacs-orgmode@gnu.org; Fri, 07 Mar 2014 16:38:20 +0100 Received: from vpn-2039.gwdg.de ([134.76.2.39]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 07 Mar 2014 16:38:20 +0100 Received: from andreas.leha by vpn-2039.gwdg.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 07 Mar 2014 16:38:20 +0100 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Hi Rehan, Rehan Iftikhar 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=<> echo "${token}.ext" #+end_src #+results: usethetokenvianoweb : uagpb.ext --8<---------------cut here---------------end--------------->8--- HTH, Andreas