Using sudo in org-babel
Here's a simple way of using sudo in org-babel:
#+NAME: just-open #+BEGIN_SRC shell :tangle no :dir /sudo::~mark/writing exec 2>&1 mkdir -p perf && cd perf /home/mark/.guix-profile/bin/perf stat -e 'block:*' ../open-perf #+END_SRC
- Use
:tangle noto exlude this snippet from being tangled - Use
:dir /sudo::~mark/writingto activate TRAMP (/sudo) and set the current path that is to be used. Note: paths relative to the document didn't work out for me - Use
exec 2>&to redirectstderrtostdoutto capture the entire output of your command, not juststdout - Finally use the full path to the command, because your user environment may be different then the
sudoenvironment you're running in.
That's it. Tested on org-mode 9 and emacs 25.3.