Re: ob-shell sessions will send final echo '...' as input key sequence when previous command reads input interactively (was: [Need Help] Error to evaluate "mpv" command in inline src block)

2023-05-03 Thread Ihor Radchenko
Matt  writes:

>  > Matt, maybe you have some ideas about this edge case?
>
> I have no other ideas within the current ob-shell implementation.  As for 
> modifications, I have the following thoughts.
>
> First, how might we state the problem for this edge case?
>
> To me, it looks like, "How can the ob-shell :async option manage interactive 
> input?"  Do you agree with this formulation?  If not, how do you see it 
> differently?

It is not about :async per se. Rather about using :session.

A simple reproducer is

#+begin_src bash :session test
mpv "/path/to/some/video"
m_
#+end_src

Basically, when you send multiline command in comint buffer without
waiting for each line to finish, the following line may be read by the
running command if that command is interactive.

It is similar to a situation when you run a normal terminal like

$ mpv "..."


$ m_ 

> One thought is to update :async to work with the :stdin option so that
> the block is run as a script. Currently, :stdin runs synchronously in
> a separate shell. We might be able to grab the script's output and put
> it into the session buffer. See how the following runs in a temporary
> shell, regardless of the :session/:async options.

Avoiding session altogether will indeed solve the problem, as :session
is the place where the problem lies.

Adding :stdin support is also an interesting idea, even out of scope of
this discussion.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



Re: ob-shell sessions will send final echo '...' as input key sequence when previous command reads input interactively (was: [Need Help] Error to evaluate "mpv" command in inline src block)

2023-05-02 Thread Matt
  On Tue, 02 May 2023 00:17:51 -0400  Christopher M. Miles  wrote --- 

 > Indeed, this option solved the problem real neat.
 > I'm surprised by your knowledge and digging problem skill.
 > I have to say a big TANKS to you. THANKS, THANKS, THANKS. Hahaha

My thanks as well to everyone who helped.  I'm tied up with personal matters 
currently and am only seeing this thread now.

  On Mon, 01 May 2023 07:36:23 -0400  Ihor Radchenko  wrote --- 
 
 > The only way I know how to work around this is a giant one-liner like
 > echo ''; ; echo '...'
 > 
 > However, (1) ";" may not work in some shells; (2)  may
 > contain multiple lines, leading to the same issue.
 > 
 > Matt, maybe you have some ideas about this edge case?

I have no other ideas within the current ob-shell implementation.  As for 
modifications, I have the following thoughts.

First, how might we state the problem for this edge case?

To me, it looks like, "How can the ob-shell :async option manage interactive 
input?"  Do you agree with this formulation?  If not, how do you see it 
differently?

One thought is to update :async to work with the :stdin option so that the 
block is run as a script.  Currently, :stdin runs synchronously in a separate 
shell.  We might be able to grab the script's output and put it into the 
session buffer.  See how the following runs in a temporary shell, regardless of 
the :session/:async options.

#+name: answers
Matt
yes

#+begin_src sh :stdin answers :results output :session *test* :async
echo -n "What's your name?"
read -r name
echo
echo "Hello, $name!"

echo -n "Would you like to continue?"
read -r continue
echo

if [ $continue == 'yes' ]; then
echo "Continuing..."
sleep 3
echo "Process complete"
else
echo "Aborted"
fi
#+end_src

#+RESULTS:
: What's your name?
: Hello, Matt!
: Would you like to continue?
: Continuing...
: Process complete



ob-shell sessions will send final echo '...' as input key sequence when previous command reads input interactively (was: [Need Help] Error to evaluate "mpv" command in inline src block)

2023-05-01 Thread Ihor Radchenko
"Christopher M. Miles"  writes:

>> So, it looks to me like mpv is somehow trying to interpret "echo" commands 
>> the
>> ob-shell is sending after "mpv " is executed:
> ...
> Don't know ob-shell which part did your said "echo" commands. I don't
> know where to dig this issue. Hope you can help. Thanks for your
> reproducing problem and dive in.

The underlying issue lies within how comint works + the fact that mpv
reads key input from terminal.

Try the following:

1. emacs -Q
2. M-x shell
3. cd /path/to/your/video 
4. Copy the following into kill ring
-
mpv "枕刀歌/《枕刀歌》SE05 江海阔 歌谣哼唱.mp4"
m_
-
5. (in the shell buffer): C-y 
6. Observe mpv playing no sound and video
7. Press m_ to restore video and sound.

I am not sure if we can do much about this though.
We run async shell commands in sessions using

(insert (format ob-shell-async-indicator "start" uuid))
(comint-send-input nil t)
(insert (org-trim body))
(comint-send-input nil t)
(insert (format ob-shell-async-indicator "end" uuid))
(comint-send-input nil t)

which sends

"echo ''

echo '...'"

to comint terminal session.

The last echo '...' in this case is interpreted as key input by mpv -
symbol by symbol.

The only way I know how to work around this is a giant one-liner like
echo ''; ; echo '...'

However, (1) ";" may not work in some shells; (2)  may
contain multiple lines, leading to the same issue.

Matt, maybe you have some ideas about this edge case?

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at