From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dan Davison Subject: Re: [Babel] Debugging shell code that misbehaves Date: Tue, 19 Oct 2010 11:18:25 +0100 Message-ID: <87d3r6h4em.fsf@stats.ox.ac.uk> References: <80zkuhkk67.fsf@mundaneum.com> <87d3rcrjy8.fsf@stats.ox.ac.uk> <808w1v9o5o.fsf@mundaneum.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from [140.186.70.92] (port=43739 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P89HY-0002MB-Ai for emacs-orgmode@gnu.org; Tue, 19 Oct 2010 06:19:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P89HO-0002Sw-A2 for emacs-orgmode@gnu.org; Tue, 19 Oct 2010 06:19:00 -0400 Received: from plane.gmane.org ([80.91.229.3]:46843) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P89HO-0002SW-4F for emacs-orgmode@gnu.org; Tue, 19 Oct 2010 06:18:50 -0400 Received: from public by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1P89HH-0008Cm-6a for emacs-orgmode@gnu.org; Tue, 19 Oct 2010 12:18:43 +0200 In-Reply-To: <808w1v9o5o.fsf@mundaneum.com> (=?utf-8?Q?=22S=C3=A9bastien?= Vauban"'s message of "Mon, 18 Oct 2010 23:38:59 +0200") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: =?utf-8?Q?S=C3=A9bastien?= Vauban Cc: public-emacs-orgmode-mXXj517/zsQ@plane.gmane.org S=C3=A9bastien Vauban writes: > Hi Dan, > > Dan Davison wrote: >> S=C3=A9bastien Vauban writes: >> >>> #+TITLE: Debugging shell code that misbehaves >>> #+DATE: 2010-10-14 >>> #+LANGUAGE: en_US >>> >>> * Use case >>> >>> Let's say that: >>> >>> - This file is in =3D~/Client/Spec=3D >>> - I'm working on such a chunk of code: >>> >>> #+begin_src sh :results output :exports results >>> grep indAllocType ../Ontology/champs.csv |\ >>> iconv -f LATIN1 -t UTF8 |\ >>> tr "[]" "|" | cut -d "|" -f 2 | cut -d " " -f 2- |\ >>> sed 's%, %\n%g' >>> #+end_src >>> >>> and that, when executing it, I've got an error with not enough context = for me >>> to understand what's the problem is. >>> >>> Sneak preview: under Cygwin, the =3Dto=3D language (of the =3Diconv=3D = command) must >>> be =3DUTF-8=3D in the above case (with a dash). >>> >>> * Debug it >>> >>> So, in order to debug, I decide to add a =3Dsession=3D argument: >>> >>> #+begin_src sh :results output :exports results :session sva >>> grep indAllocType ../Ontology/champs.csv |\ >>> iconv -f LATIN1 -t UTF8 |\ >>> tr "[]" "|" | cut -d "|" -f 2 | cut -d " " -f 2- |\ >>> sed 's%, %\n%g' >>> #+end_src >>> >>> and, there, something totally different is occurring: =3Dgrep=3D is not= finding >>> the file anymore. >>> >>> Why? Because adding the session argument makes the code executed from m= y *home >>> directory*, while it was executed from the *document's directory* in th= e first >>> place. >> >> This would be a bug. For me (ubuntu), the session does start up in the >> document's directory. Perhaps the emacs shell session behaves differentl= y on >> your operating system (cygwin?)? > > How could we proove who's doing that effect? Do you have an idea for tes= ting > this, and identifying what portion of code (be it Org, Babel or Cygwin) w= ould > need to be fixed or customized? Hi Seb, What happens if you do: 1. Kill all current *shell* sessions/buffers 2. Use M-x cd to change the emacs default-directory 3. Issue M-x shell 4. Query the current directory of the shell session with pwd Dan > > >>> So, this is not the right way to debug... as *conditions do change*. >> >> but should not >> >>> >>> * Solution? >>> >>> What's the right solution for such a case? >> >> Fix the bug. But failing that, > > Good... > > >>> - Putting a full path to the file =3Dchamps.csv=3D (instead of the rela= tive one) >>> is not OK for me, as all of this is under SVN, and I want this to be >>> executable on someone's else PC (even if placed somewhere else). >>> >>> - Add an explicit =3Dcd=3D to the right place, before the commands exec= ute. Not >>> possible, for the same reason as above. >> >> does it help to use a :dir header argument to specify default-directory >> for the session? > > Such a dir spec does not seem to be respected: > > #+begin_src sh :results output :exports results :session sva :dir /cygdri= ve/c/home/sva/Projects/Client > grep indAllocType ../Ontology/champs.csv |\ > iconv -f LATIN1 -t UTF-8 |\ > tr "[]" "|" | cut -d "|" -f 2 | cut -d " " -f 2- |\ > sed 's%, %\n%g' > #+end_src > > Doing pwd in the session buffer, and I see I'm still in ~ (/cygdrive/c/ho= me/sva). > > Moreover, no, that would not, as I cannot predict where the file will be > located on my colleagues' machines, except if I could add there a relative > spec such as ":dir ./". > > Best regards, > Seb