I don't quite understand the details yet, but it turns out that for both ssh
and adb
, you need to prevent them from reading stdin
- otherwise, they block waiting for input. The confusing part is that it is not always necessary, but it is necessary in some (most?) cases, so it's better to be safe than sorry.
In the case of ssh
, I got the same behavior (blocking) when I tried to ssh
to localhost
. ssh
has a flag -n
(or a setting StdinNull
) that allows you to tell it to ignore stdin
.
It turns out that adb
has a similar flag in its shell
subcommand, also denoted by -n
(surely, not a coincidence).
So the final outcome is that both source blocks (sh
and bash
) will work fine, as long as you provide the flag:
#+begin_src sh :results output
echo Start
out=$(ssh -n localhost date)
echo $out
echo Done
#+end_src
#+RESULTS:
: Start
: Thu Dec 15 01:24:31 AM EST 2022
: Done
#+begin_src bash :results output
echo Start
out=$(ssh -n localhost date)
echo $out
echo Done
#+end_src
#+RESULTS:
: Start
: Thu Dec 15 01:24:36 AM EST 2022
: Done
#+begin_src sh :results output
echo Start
out=$(adb shell -n date)
echo $out
echo Done
#+end_src
#+RESULTS:
: Start
: Thu Dec 15 01:25:14 EST 2022
: Done
#+begin_src bash :results output
echo Start
out=$(adb shell -n date)
echo $out
echo Done
#+end_src
#+RESULTS:
: Start
: Thu Dec 15 01:25:19 EST 2022
: Done
ssh
command to a remote host that you have access to (ssh remote.host.example.com date
) instead of theadb
command and see if the shell makes any difference. If not, I would suspectadb
but I cannot test that.adb
and although running theadb shell date
command from the command line works fine, I cannot get output from the source block with eithersh
orbash
. Doing a similarssh
command works with both. There is funkiness galore, but I'm not sure where.adb
withssh
, but they have similar properties, so I wanted to test the source blocks usingssh
, rather thanadb
. I just didout=$(ssh <remotehost> date)
where <remotehost> is a machine I could ssh into: that works with bothsh
andbash
code blocks. However, neither thesh
code block nor thebash
code block worked without=$(adb shell date)
- but I don't know why that is the case.