0

Please consider the org-babel block below, where I dump a MySQL table:

#+begin_src sh :results value file :file dump.sql
mysqldump -u root -h 0.0.0.0 -P 49321 -proot db_name tbl_name
#+end_src

Running this command in my terminal gives me the output I expect: the raw SQL that I can redirect into a file. However, when I run it in that babel block, the file "dump.sql" contains only the character "2".

Changing the collection option to "output" makes emacs complain that it "Couldn't execute 'SELECT COLUMN_NAME,...". I'm sure there is some combination of results options that would give me what I want, but they elude me at the moment.

1 Answer 1

1

It seems I should have done a few more minutes of research. I found my solution with the help of an answer to a similar question on these forums: I have to take advantage of the ":prologue", and ":epilogue" parameters to properly handle the command's output, and change the collection option to "output":

#+begin_src sh :results output file raw :file dump.sql :prologue "2>/dev/null" :epilogue ":"
mysqldump -u root -h 0.0.0.0 -P 49321 -proot cf_dev sforum_contacts
#+end_src

I had no idea these options existed, and don't understand what they do exactly -- the prologue option seems akin to appending it's value to each command in your block, and I have no idea what the epilogue option does.

3
  • You should read the manual Instead of just cargo–culting from someone else’s question. In particular those :prologue and :epilogue options are probably not doing anything useful for you! They allow you to put stuff (in this case shell commands, since this is an “sh” source block) before and after the content of the source block before actually sending it to a shell. So yours is like running the script 2>/dev/null; mysqldump …; :. What really fixed it for you is changing “:results value” to “:results output”.
    – db48x
    Jan 21, 2023 at 4:05
  • I said in my question that only changing the collection option to output caused emacs to complain that it couldn't execute 'SELECT COLUMN_NAME,...". The prologue option caused the block to do what I wanted, but I do confess that I probably don't need the epilogue option.
    – daraul
    Jan 21, 2023 at 11:33
  • :prologue "2>/dev/null" couldn’t have fixed it because all that does is redirect the stderr of an empty command to /dev/null. Maybe it was really :prologue "exec 2>/dev/null"?
    – db48x
    Jan 21, 2023 at 17:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.