* [Need Help] Error to evaluate "mpv" command in inline src block
@ 2023-04-30 4:27 stardiviner
2023-04-30 4:46 ` Ruijie Yu via General discussions about Org-mode.
2023-04-30 14:52 ` Ihor Radchenko
0 siblings, 2 replies; 24+ messages in thread
From: stardiviner @ 2023-04-30 4:27 UTC (permalink / raw)
To: Org-mode
[-- Attachment #1: Type: text/plain, Size: 5687 bytes --]
*** Reproduce and experience log
I have Emacs Org mode config like bellowing to auto evaluate inline src
block when Org headline cycle expanded.
#+begin_src emacs-lisp
;;; auto evaluate inline source block in property "EVAL".
(defcustom org-property-eval-keyword "EVAL"
"A property keyword for evaluate code."
:type 'string
:safe #'stringp
:group 'org)
(add-to-list 'org-default-properties org-property-eval-keyword)
(defun org-property-eval-on-cycle-expand (&optional state)
"Evaluate Org inline source block in property value on headline cycle
expand."
(when (memq state '(children subtree))
(if-let ((inline-src-block (org-entry-get nil org-property-eval-keyword
nil)))
(with-temp-buffer
(insert inline-src-block)
(goto-char (point-min))
(let* ((context (org-element-context))
(lang (org-element-property :language context))
(type (org-element-type context))
(src-block-info (org-babel-get-src-block-info nil
context)))
(when (eq type 'inline-src-block)
(org-babel-execute-src-block
nil src-block-info
(pcase lang
("sh" `((:session . ,(make-temp-name " *ob-sh-inline-async
(sh) ")) (:async . "yes") (:results . "silent")))
("shell" `((:session . ,(make-temp-name "
*ob-sh-inline-async (shell) ")) (:async . "yes") (:results . "silent")))
("bash" `((:session . ,(make-temp-name "
*ob-sh-inline-async (bash) ")) (:async . "yes") (:results . "silent")))
("zsh" `((:session . ,(make-temp-name "
*ob-sh-inline-async (zsh) ")) (:async . "yes") (:results . "silent")))
(_ '((:results . "none")))))))))))
(add-hook 'org-cycle-hook #'org-property-eval-on-cycle-expand)
#+end_src
I have example Org file like bellowing.
Here is the testing Org content:
#+begin_src org
,* 《枕刀歌》
:PROPERTIES:
:DATE: [2021-05-13 Thu 20:09]
:Douban: https://movie.douban.com/subject/35350794/
:DIR: 枕刀歌
:EVAL: src_sh{mpv "枕刀歌/《枕刀歌》SE05 江海阔 歌谣哼唱.mp4"}
:END:
#+end_src
When I press Tab key to expand upper headline. I check the inline src block
session buffer, here is the output:
#+begin_example
bash-5.2$ bash-5.2$ PROMPT_COMMAND=;PS1="org_babel_sh_prompt> ";PS2=
org_babel_sh_prompt> echo
'ob_comint_async_shell_start_d1cc7563-be0c-4ed0-a4c2-d1b545333983'
mpv "枕刀歌/《枕刀歌》SE05 江海阔 歌谣哼唱.mp4"
echo 'ob_comint_async_shell_end_d1cc7563-be0c-4ed0-a4c2-d1b545333983'
ob_comint_async_shell_start_d1cc7563-be0c-4ed0-a4c2-d1b545333983
org_babel_sh_prompt> =[input] No key binding found for key 'c'.
[input] No key binding found for key 'h'.
[input] No key binding found for key '''.
[input] No key binding found for key 'b'.
[input] No key binding found for key 'c'.
[input] No key binding found for key 'n'.
[input] No key binding found for key 'a'.
[input] No key binding found for key 'y'.
[input] No key binding found for key 'n'.
[input] No key binding found for key 'c'.
[input] No key binding found for key 'h'.
[input] No key binding found for key 'n'.
[input] No key binding found for key 'c'.
[input] No key binding found for key 'c'.
[input] No key binding found for key '-'.
[input] No key binding found for key 'b'.
[input] No key binding found for key 'c'.
[input] No key binding found for key '-'.
[input] No key binding found for key '-'.
[input] No key binding found for key 'a'.
[input] No key binding found for key 'c'.
[input] No key binding found for key '-'.
[input] No key binding found for key 'b'.
[input] No key binding found for key '''.
Resuming playback. This behavior can be disabled with --no-resume-playback.
Video --vid=1 (*) (h264 1920x1080 25.000fps)
(+) Audio --aid=1 (*) (aac 2ch 48000Hz)
AO: [coreaudio] 48000Hz stereo 2ch floatp
Mute: yes
C-c C-c>
Saving state.
Exiting... (Quit)
org_babel_sh_prompt> echo $SHELL
/bin/zsh
org_babel_sh_prompt>
#+end_example
Then I try to replace the "mpv" shell command with another command without
need to invoke desktop GUI. Like bellowing Org content:
#+begin_src org
,* 《枕刀歌》
:PROPERTIES:
:DATE: [2021-05-13 Thu 20:09]
:Douban: https://movie.douban.com/subject/35350794/
:DIR: 枕刀歌
:EVAL: src_sh{sleep 10; echo "done"}
:END:
#+end_src
It evaluated fine.
#+begin_example
sh-3.2$ sh-3.2$ PROMPT_COMMAND=;PS1="org_babel_sh_prompt> ";PS2=
org_babel_sh_prompt> echo
'ob_comint_async_shell_start_ca48d711-c1d3-4ec3-8e9b-072f76fc86d5'
sleep 10; echo "done"
echo 'ob_comint_async_shell_end_ca48d711-c1d3-4ec3-8e9b-072f76fc86d5'
ob_comint_async_shell_start_ca48d711-c1d3-4ec3-8e9b-072f76fc86d5
org_babel_sh_prompt> done
org_babel_sh_prompt>
ob_comint_async_shell_end_ca48d711-c1d3-4ec3-8e9b-072f76fc86d5
org_babel_sh_prompt>
#+end_example
Even I testing using content directly instead of in "EVAL" property like
bellowing:
#+begin_src org
Test src_sh{pwd} {{{results(=/Users/stardiviner/Org/Wiki/ACG/Anime/Anime
Videos=)}}}
#+end_src
It works fine.
But I failed to execute mpv command:
#+begin_src org
Test src_sh{mpv "枕刀歌/《枕刀歌》SE05 江海阔 歌谣哼唱.mp4"}
#+end_src
I don't understand where get wrong. And what's the reason.
[stardiviner] <Hack this world!> GPG key ID: 47C32433
IRC(freeenode): stardiviner Twitter: @numbchild
Key fingerprint = 9BAA 92BC CDDD B9EF 3B36 CB99 B8C4 B8E5 47C3 2433
Blog: http://stardiviner.github.io/
[-- Attachment #2: Type: text/html, Size: 7497 bytes --]
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [Need Help] Error to evaluate "mpv" command in inline src block
2023-04-30 4:27 [Need Help] Error to evaluate "mpv" command in inline src block stardiviner
@ 2023-04-30 4:46 ` Ruijie Yu via General discussions about Org-mode.
2023-04-30 10:59 ` Christopher M. Miles
2023-04-30 14:52 ` Ihor Radchenko
1 sibling, 1 reply; 24+ messages in thread
From: Ruijie Yu via General discussions about Org-mode. @ 2023-04-30 4:46 UTC (permalink / raw)
To: stardiviner; +Cc: emacs-orgmode
stardiviner <numbchild@gmail.com> writes:
> I have example Org file like bellowing.
>
> Here is the testing Org content:
>
> #+begin_src org
> ,* 《枕刀歌》
> :PROPERTIES:
> :DATE: [2021-05-13 Thu 20:09]
> :Douban: https://movie.douban.com/subject/35350794/
> :DIR: 枕刀歌
> :EVAL: src_sh{mpv "枕刀歌/《枕刀歌》SE05 江海阔 歌谣哼唱.mp4"}
> :END:
> #+end_src
>
> When I press Tab key to expand upper headline. I check the inline src block session buffer, here is the output:
>
> #+begin_example
> bash-5.2$ bash-5.2$ PROMPT_COMMAND=;PS1="org_babel_sh_prompt> ";PS2=
> org_babel_sh_prompt> echo 'ob_comint_async_shell_start_d1cc7563-be0c-4ed0-a4c2-d1b545333983'
> mpv "枕刀歌/《枕刀歌》SE05 江海阔 歌谣哼唱.mp4"
> echo 'ob_comint_async_shell_end_d1cc7563-be0c-4ed0-a4c2-d1b545333983'
> ob_comint_async_shell_start_d1cc7563-be0c-4ed0-a4c2-d1b545333983
> org_babel_sh_prompt> =[input] No key binding found for key 'c'.
> [input] No key binding found for key 'h'.
> [input] No key binding found for key '''.
> [input] No key binding found for key 'b'.
> [input] No key binding found for key 'c'.
> [input] No key binding found for key 'n'.
> [input] No key binding found for key 'a'.
> [input] No key binding found for key 'y'.
> [input] No key binding found for key 'n'.
> [input] No key binding found for key 'c'.
> [input] No key binding found for key 'h'.
> [input] No key binding found for key 'n'.
> [input] No key binding found for key 'c'.
> [input] No key binding found for key 'c'.
> [input] No key binding found for key '-'.
> [input] No key binding found for key 'b'.
> [input] No key binding found for key 'c'.
> [input] No key binding found for key '-'.
> [input] No key binding found for key '-'.
> [input] No key binding found for key 'a'.
> [input] No key binding found for key 'c'.
> [input] No key binding found for key '-'.
> [input] No key binding found for key 'b'.
> [input] No key binding found for key '''.
>
> Resuming playback. This behavior can be disabled with --no-resume-playback.
>
> Video --vid=1 (*) (h264 1920x1080 25.000fps)
> (+) Audio --aid=1 (*) (aac 2ch 48000Hz)
> AO: [coreaudio] 48000Hz stereo 2ch floatp
> Mute: yes
>
> C-c C-c>
> Saving state.
>
> Exiting... (Quit)
> org_babel_sh_prompt> echo $SHELL
> /bin/zsh
> org_babel_sh_prompt>
> #+end_example
>
> Then I try to replace the "mpv" shell command with another command without need to invoke desktop GUI. Like bellowing Org content:
>
> #+begin_src org
> ,* 《枕刀歌》
> :PROPERTIES:
> :DATE: [2021-05-13 Thu 20:09]
> :Douban: https://movie.douban.com/subject/35350794/
> :DIR: 枕刀歌
> :EVAL: src_sh{sleep 10; echo "done"}
> :END:
> #+end_src
>
> It evaluated fine.
Try putting "cat" there. I suspect something is fed into the stdin of
the process.
--
Best,
RY
[Please note that this mail might go to spam due to some
misconfiguration in my mail server -- still investigating.]
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [Need Help] Error to evaluate "mpv" command in inline src block
2023-04-30 4:46 ` Ruijie Yu via General discussions about Org-mode.
@ 2023-04-30 10:59 ` Christopher M. Miles
0 siblings, 0 replies; 24+ messages in thread
From: Christopher M. Miles @ 2023-04-30 10:59 UTC (permalink / raw)
To: Ruijie Yu; +Cc: stardiviner, emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 484 bytes --]
Ruijie Yu <ruijie@netyu.xyz> writes:
> Try putting "cat" there. I suspect something is fed into the stdin of
> the process.
Can you explain in detailed? Don't know how to put command "cat" in my situation.
--
[ stardiviner ]
I try to make every word tell the meaning that I want to express without misunderstanding.
Blog: https://stardiviner.github.io/
IRC(libera.chat, freenode): stardiviner, Matrix: stardiviner
GPG: F09F650D7D674819892591401B5DF1C95AE89AC3
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [Need Help] Error to evaluate "mpv" command in inline src block
2023-04-30 4:27 [Need Help] Error to evaluate "mpv" command in inline src block stardiviner
2023-04-30 4:46 ` Ruijie Yu via General discussions about Org-mode.
@ 2023-04-30 14:52 ` Ihor Radchenko
2023-05-01 3:39 ` Christopher M. Miles
1 sibling, 1 reply; 24+ messages in thread
From: Ihor Radchenko @ 2023-04-30 14:52 UTC (permalink / raw)
To: stardiviner; +Cc: Org-mode
stardiviner <numbchild@gmail.com> writes:
> I have Emacs Org mode config like bellowing to auto evaluate inline src
> block when Org headline cycle expanded.
> ...
> Here is the testing Org content:
> ...
>
> When I press Tab key to expand upper headline. I check the inline src block
> session buffer, here is the output:
>
> #+begin_example
> bash-5.2$ bash-5.2$ PROMPT_COMMAND=;PS1="org_babel_sh_prompt> ";PS2=
> org_babel_sh_prompt> echo
> 'ob_comint_async_shell_start_d1cc7563-be0c-4ed0-a4c2-d1b545333983'
> mpv "枕刀歌/《枕刀歌》SE05 江海阔 歌谣哼唱.mp4"
> echo 'ob_comint_async_shell_end_d1cc7563-be0c-4ed0-a4c2-d1b545333983'
> ob_comint_async_shell_start_d1cc7563-be0c-4ed0-a4c2-d1b545333983
> org_babel_sh_prompt> =[input] No key binding found for key 'c'.
> ...
> Resuming playback. This behavior can be disabled with --no-resume-playback.
>
> Video --vid=1 (*) (h264 1920x1080 25.000fps)
> (+) Audio --aid=1 (*) (aac 2ch 48000Hz)
> AO: [coreaudio] 48000Hz stereo 2ch floatp
> Mute: yes
>
>
>
> C-c C-c>
> Saving state.
>
> Exiting... (Quit)
> org_babel_sh_prompt> echo $SHELL
> /bin/zsh
> org_babel_sh_prompt>
> #+end_example
It looks like mpv command is running.
> ...
> But I failed to execute mpv command:
>
> #+begin_src org
> Test src_sh{mpv "枕刀歌/《枕刀歌》SE05 江海阔 歌谣哼唱.mp4"}
> #+end_src
May you elaborate what you mean by "failed"?
--
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [Need Help] Error to evaluate "mpv" command in inline src block
2023-04-30 14:52 ` Ihor Radchenko
@ 2023-05-01 3:39 ` Christopher M. Miles
2023-05-01 7:45 ` Ihor Radchenko
0 siblings, 1 reply; 24+ messages in thread
From: Christopher M. Miles @ 2023-05-01 3:39 UTC (permalink / raw)
To: Ihor Radchenko; +Cc: stardiviner, Org-mode
[-- Attachment #1: Type: text/plain, Size: 2025 bytes --]
Ihor Radchenko <yantar92@posteo.net> writes:
> stardiviner <numbchild@gmail.com> writes:
>
>> I have Emacs Org mode config like bellowing to auto evaluate inline src
>> block when Org headline cycle expanded.
>> ...
>> Here is the testing Org content:
>> ...
>>
>> When I press Tab key to expand upper headline. I check the inline src block
>> session buffer, here is the output:
>>
>> #+begin_example
>> bash-5.2$ bash-5.2$ PROMPT_COMMAND=;PS1="org_babel_sh_prompt> ";PS2=
>> org_babel_sh_prompt> echo
>> 'ob_comint_async_shell_start_d1cc7563-be0c-4ed0-a4c2-d1b545333983'
>> mpv "枕刀歌/《枕刀歌》SE05 江海阔 歌谣哼唱.mp4"
>> echo 'ob_comint_async_shell_end_d1cc7563-be0c-4ed0-a4c2-d1b545333983'
>> ob_comint_async_shell_start_d1cc7563-be0c-4ed0-a4c2-d1b545333983
>> org_babel_sh_prompt> =[input] No key binding found for key 'c'.
>> ...
>> Resuming playback. This behavior can be disabled with --no-resume-playback.
>>
>> Video --vid=1 (*) (h264 1920x1080 25.000fps)
>> (+) Audio --aid=1 (*) (aac 2ch 48000Hz)
>> AO: [coreaudio] 48000Hz stereo 2ch floatp
>> Mute: yes
>>
>>
>>
>> C-c C-c>
>> Saving state.
>>
>> Exiting... (Quit)
>> org_babel_sh_prompt> echo $SHELL
>> /bin/zsh
>> org_babel_sh_prompt>
>> #+end_example
>
> It looks like mpv command is running.
>
Yes, check out the output from the sh session buffer, we can confirm mpv is executed.
But seems got weird error.
>> ...
>> But I failed to execute mpv command:
>>
>> #+begin_src org
>> Test src_sh{mpv "枕刀歌/《枕刀歌》SE05 江海阔 歌谣哼唱.mp4"}
>> #+end_src
>
> May you elaborate what you mean by "failed"?
The "failed" means the MPV video player window does not show up, no video, no audio.
--
[ stardiviner ]
I try to make every word tell the meaning that I want to express without misunderstanding.
Blog: https://stardiviner.github.io/
IRC(libera.chat, freenode): stardiviner, Matrix: stardiviner
GPG: F09F650D7D674819892591401B5DF1C95AE89AC3
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [Need Help] Error to evaluate "mpv" command in inline src block
2023-05-01 3:39 ` Christopher M. Miles
@ 2023-05-01 7:45 ` Ihor Radchenko
2023-05-01 10:46 ` Christopher M. Miles
2023-05-01 10:50 ` [Need Help] Error to evaluate "mpv" command in inline src block Christopher M. Miles
0 siblings, 2 replies; 24+ messages in thread
From: Ihor Radchenko @ 2023-05-01 7:45 UTC (permalink / raw)
To: Christopher M. Miles; +Cc: Org-mode
"Christopher M. Miles" <numbchild@gmail.com> writes:
>>> But I failed to execute mpv command:
>>>
>>> #+begin_src org
>>> Test src_sh{mpv "枕刀歌/《枕刀歌》SE05 江海阔 歌谣哼唱.mp4"}
>>> #+end_src
>>
>> May you elaborate what you mean by "failed"?
>
> The "failed" means the MPV video player window does not show up, no video, no audio.
Interesting. I tried harder to reproduce following your steps.
Now, I used a video file with CJK name:
* 《枕刀歌》
:PROPERTIES:
:DATE: [2021-05-13 Thu 20:09]
:Douban: https://movie.douban.com/subject/35350794/
:DIR: 鸟瞰古
:EVAL: src_sh{mpv "鸟瞰古/【人文纪录片】鸟瞰古代中国.Ancient.China.from.Above P1 鸟瞰古代中国.Ancient.China.from.Above.S01....flv"}
:END:
And I can reproduce - mpv windows shows up, but no video and no sound.
Then, I tried to open the same video in usual way... and still no sound
- until I press "m" to unmute.
So, it looks to me like mpv is somehow trying to interpret "echo" commands the
ob-shell is sending after "mpv ...." is executed:
ob_comint_async_shell_start_d1cc7563-be0c-4ed0-a4c2-d1b545333983
org_babel_sh_prompt> =[input] No key binding found for key 'c'.
...
[input] No key binding found for key '''.
[input] No key binding found for key 'b'.
...
[input] No key binding found for key '''.
These "No key binding found statements" a likely from "echo" commands
attempted to be sent to the terminal.
--
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [Need Help] Error to evaluate "mpv" command in inline src block
2023-05-01 7:45 ` Ihor Radchenko
@ 2023-05-01 10:46 ` Christopher M. Miles
2023-05-01 11:39 ` 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) Ihor Radchenko
2023-05-01 10:50 ` [Need Help] Error to evaluate "mpv" command in inline src block Christopher M. Miles
1 sibling, 1 reply; 24+ messages in thread
From: Christopher M. Miles @ 2023-05-01 10:46 UTC (permalink / raw)
To: Ihor Radchenko; +Cc: Christopher M. Miles, Org-mode
[-- Attachment #1: Type: text/plain, Size: 4152 bytes --]
Ihor Radchenko <yantar92@posteo.net> writes:
> "Christopher M. Miles" <numbchild@gmail.com> writes:
>
>>>> But I failed to execute mpv command:
>>>>
>>>> #+begin_src org
>>>> Test src_sh{mpv "枕刀歌/《枕刀歌》SE05 江海阔 歌谣哼唱.mp4"}
>>>> #+end_src
>>>
>>> May you elaborate what you mean by "failed"?
>>
>> The "failed" means the MPV video player window does not show up, no video, no audio.
>
> Interesting. I tried harder to reproduce following your steps.
> Now, I used a video file with CJK name:
>
> * 《枕刀歌》
> :PROPERTIES:
> :DATE: [2021-05-13 Thu 20:09]
> :Douban: https://movie.douban.com/subject/35350794/
> :DIR: 鸟瞰古
> :EVAL: src_sh{mpv "鸟瞰古/【人文纪录片】鸟瞰古代中国.Ancient.China.from.Above P1 鸟瞰古代中国.Ancient.China.from.Above.S01....flv"}
> :END:
>
> And I can reproduce - mpv windows shows up, but no video and no sound.
> Then, I tried to open the same video in usual way... and still no sound
> - until I press "m" to unmute.
>
> So, it looks to me like mpv is somehow trying to interpret "echo" commands the
> ob-shell is sending after "mpv ...." is executed:
>
> ob_comint_async_shell_start_d1cc7563-be0c-4ed0-a4c2-d1b545333983
> org_babel_sh_prompt> =[input] No key binding found for key 'c'.
> ...
> [input] No key binding found for key '''.
> [input] No key binding found for key 'b'.
> ...
> [input] No key binding found for key '''.
>
> These "No key binding found statements" a likely from "echo" commands
> attempted to be sent to the terminal.
I have similar output in session buffer too. Here is the output in my session buffer.
When I press Tab key to expand upper headline. I check the inline src block session buffer, here is the output:
#+begin_example
bash-5.2$ bash-5.2$ PROMPT_COMMAND=;PS1="org_babel_sh_prompt> ";PS2=
org_babel_sh_prompt> echo 'ob_comint_async_shell_start_d1cc7563-be0c-4ed0-a4c2-d1b545333983'
mpv "枕刀歌/《枕刀歌》SE05 江海阔 歌谣哼唱.mp4"
echo 'ob_comint_async_shell_end_d1cc7563-be0c-4ed0-a4c2-d1b545333983'
ob_comint_async_shell_start_d1cc7563-be0c-4ed0-a4c2-d1b545333983
org_babel_sh_prompt> =[input] No key binding found for key 'c'.
[input] No key binding found for key 'h'.
[input] No key binding found for key '''.
[input] No key binding found for key 'b'.
[input] No key binding found for key 'c'.
[input] No key binding found for key 'n'.
[input] No key binding found for key 'a'.
[input] No key binding found for key 'y'.
[input] No key binding found for key 'n'.
[input] No key binding found for key 'c'.
[input] No key binding found for key 'h'.
[input] No key binding found for key 'n'.
[input] No key binding found for key 'c'.
[input] No key binding found for key 'c'.
[input] No key binding found for key '-'.
[input] No key binding found for key 'b'.
[input] No key binding found for key 'c'.
[input] No key binding found for key '-'.
[input] No key binding found for key '-'.
[input] No key binding found for key 'a'.
[input] No key binding found for key 'c'.
[input] No key binding found for key '-'.
[input] No key binding found for key 'b'.
[input] No key binding found for key '''.
Resuming playback. This behavior can be disabled with --no-resume-playback.
Video --vid=1 (*) (h264 1920x1080 25.000fps)
(+) Audio --aid=1 (*) (aac 2ch 48000Hz)
AO: [coreaudio] 48000Hz stereo 2ch floatp
Mute: yes
C-c C-c>
Saving state.
Exiting... (Quit)
org_babel_sh_prompt> echo $SHELL
/bin/zsh
org_babel_sh_prompt>
#+end_example
I also try to add "sleep 1;" command before "mpv ..." command to delay
mpv executing. Still not success.
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.
--
[ stardiviner ]
I try to make every word tell the meaning that I want to express without misunderstanding.
Blog: https://stardiviner.github.io/
IRC(libera.chat, freenode): stardiviner, Matrix: stardiviner
GPG: F09F650D7D674819892591401B5DF1C95AE89AC3
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [Need Help] Error to evaluate "mpv" command in inline src block
2023-05-01 7:45 ` Ihor Radchenko
2023-05-01 10:46 ` Christopher M. Miles
@ 2023-05-01 10:50 ` Christopher M. Miles
1 sibling, 0 replies; 24+ messages in thread
From: Christopher M. Miles @ 2023-05-01 10:50 UTC (permalink / raw)
To: Ihor Radchenko; +Cc: Christopher M. Miles, Org-mode
[-- Attachment #1: Type: text/plain, Size: 1926 bytes --]
Ihor Radchenko <yantar92@posteo.net> writes:
> "Christopher M. Miles" <numbchild@gmail.com> writes:
>
>>>> But I failed to execute mpv command:
>>>>
>>>> #+begin_src org
>>>> Test src_sh{mpv "枕刀歌/《枕刀歌》SE05 江海阔 歌谣哼唱.mp4"}
>>>> #+end_src
>>>
>>> May you elaborate what you mean by "failed"?
>>
>> The "failed" means the MPV video player window does not show up, no video, no audio.
>
> Interesting. I tried harder to reproduce following your steps.
> Now, I used a video file with CJK name:
>
> * 《枕刀歌》
> :PROPERTIES:
> :DATE: [2021-05-13 Thu 20:09]
> :Douban: https://movie.douban.com/subject/35350794/
> :DIR: 鸟瞰古
> :EVAL: src_sh{mpv "鸟瞰古/【人文纪录片】鸟瞰古代中国.Ancient.China.from.Above P1 鸟瞰古代中国.Ancient.China.from.Above.S01....flv"}
> :END:
>
> And I can reproduce - mpv windows shows up, but no video and no sound.
> Then, I tried to open the same video in usual way... and still no sound
> - until I press "m" to unmute.
>
> So, it looks to me like mpv is somehow trying to interpret "echo" commands the
> ob-shell is sending after "mpv ...." is executed:
>
> ob_comint_async_shell_start_d1cc7563-be0c-4ed0-a4c2-d1b545333983
> org_babel_sh_prompt> =[input] No key binding found for key 'c'.
> ...
> [input] No key binding found for key '''.
> [input] No key binding found for key 'b'.
> ...
> [input] No key binding found for key '''.
>
> These "No key binding found statements" a likely from "echo" commands
> attempted to be sent to the terminal.
Do you think this issue is from Emacs shell part or mpv part?
--
[ stardiviner ]
I try to make every word tell the meaning that I want to express without misunderstanding.
Blog: https://stardiviner.github.io/
IRC(libera.chat, freenode): stardiviner, Matrix: stardiviner
GPG: F09F650D7D674819892591401B5DF1C95AE89AC3
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]
^ permalink raw reply [flat|nested] 24+ messages in thread
* 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 10:46 ` Christopher M. Miles
@ 2023-05-01 11:39 ` Ihor Radchenko
2023-05-01 12:50 ` ob-shell sessions will send final echo '...' as input key sequence when previous command reads input interactively Christopher M. Miles
` (3 more replies)
0 siblings, 4 replies; 24+ messages in thread
From: Ihor Radchenko @ 2023-05-01 11:39 UTC (permalink / raw)
To: Christopher M. Miles; +Cc: Org-mode, Matt
"Christopher M. Miles" <numbchild@gmail.com> 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 <RET>
4. Copy the following into kill ring
-----
mpv "枕刀歌/《枕刀歌》SE05 江海阔 歌谣哼唱.mp4"
m_
-----
5. (in the shell buffer): C-y <RET>
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 '....'
<your command>
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 '....'; <your command>; echo '...'
However, (1) ";" may not work in some shells; (2) <your command> 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 <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: ob-shell sessions will send final echo '...' as input key sequence when previous command reads input interactively
2023-05-01 11:39 ` 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) Ihor Radchenko
@ 2023-05-01 12:50 ` Christopher M. Miles
2023-05-01 13:14 ` Ihor Radchenko
2023-05-01 13:08 ` [SOLUTION] a temporary workaround solution using another language like "python" Christopher M. Miles
` (2 subsequent siblings)
3 siblings, 1 reply; 24+ messages in thread
From: Christopher M. Miles @ 2023-05-01 12:50 UTC (permalink / raw)
To: Ihor Radchenko; +Cc: Christopher M. Miles, Org-mode, Matt
[-- Attachment #1: Type: text/plain, Size: 2304 bytes --]
Ihor Radchenko <yantar92@posteo.net> writes:
> "Christopher M. Miles" <numbchild@gmail.com> 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 <RET>
> 4. Copy the following into kill ring
> -----
> mpv "枕刀歌/《枕刀歌》SE05 江海阔 歌谣哼唱.mp4"
> m_
> -----
> 5. (in the shell buffer): C-y <RET>
> 6. Observe mpv playing no sound and video
> 7. Press m_ to restore video and sound.
>
I reproduced same now. Thanks for your guide.
> 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 '....'
> <your command>
> 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 '....'; <your command>; echo '...'
>
I understand the process now, it is wrapped by ob-shell-async-indicator echo command.
> However, (1) ";" may not work in some shells; (2) <your command> may
> contain multiple lines, leading to the same issue.
I tested it (using ";") now, not working.
I might consider to use another language like python instead of sh to
execute command to play video to get around this issue. I will update
here if I success.
--
[ stardiviner ]
I try to make every word tell the meaning that I want to express without misunderstanding.
Blog: https://stardiviner.github.io/
IRC(libera.chat, freenode): stardiviner, Matrix: stardiviner
GPG: F09F650D7D674819892591401B5DF1C95AE89AC3
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]
^ permalink raw reply [flat|nested] 24+ messages in thread
* [SOLUTION] a temporary workaround solution using another language like "python"
2023-05-01 11:39 ` 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) Ihor Radchenko
2023-05-01 12:50 ` ob-shell sessions will send final echo '...' as input key sequence when previous command reads input interactively Christopher M. Miles
@ 2023-05-01 13:08 ` Christopher M. Miles
[not found] ` <35881.2693202466$1682946783@news.gmane.org>
2023-05-02 20:31 ` 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) Matt
3 siblings, 0 replies; 24+ messages in thread
From: Christopher M. Miles @ 2023-05-01 13:08 UTC (permalink / raw)
To: Ihor Radchenko; +Cc: Christopher M. Miles, Org-mode, Matt
[-- Attachment #1: Type: text/plain, Size: 973 bytes --]
I use another language "python" to replace "sh" to play video now. It successes.
Here is my example:
#+begin_src org
,* 《枕刀歌》
:PROPERTIES:
:DATE: [2021-05-13 Thu 20:09]
:Douban: https://movie.douban.com/subject/35350794/
:DIR: 枕刀歌
:EVAL: src_python{import os; video_file = "枕刀歌/《枕刀歌》SE05 江海阔 歌谣哼唱.mp4"; os.system("mpv \"%s\" " %(video_file))}
:END:
#+end_src
It's not as convenient as shell command directly but at least it works.
Seems the sh inline source block can't be used to play video using "mpv"
(I also tested other video player commands like "mplayer", "iina" etc).
So this python solution is a workaround.
--
[ stardiviner ]
I try to make every word tell the meaning that I want to express without misunderstanding.
Blog: https://stardiviner.github.io/
IRC(libera.chat, freenode): stardiviner, Matrix: stardiviner
GPG: F09F650D7D674819892591401B5DF1C95AE89AC3
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: ob-shell sessions will send final echo '...' as input key sequence when previous command reads input interactively
2023-05-01 12:50 ` ob-shell sessions will send final echo '...' as input key sequence when previous command reads input interactively Christopher M. Miles
@ 2023-05-01 13:14 ` Ihor Radchenko
2023-05-01 13:41 ` Christopher M. Miles
0 siblings, 1 reply; 24+ messages in thread
From: Ihor Radchenko @ 2023-05-01 13:14 UTC (permalink / raw)
To: Christopher M. Miles; +Cc: Org-mode, Matt
"Christopher M. Miles" <numbchild@gmail.com> writes:
> I might consider to use another language like python instead of sh to
> execute command to play video to get around this issue. I will update
> here if I success.
All you need to do is getting rid of :async and :session.
Just use :results none + "&" at the end of mpv command.
Non-session blocks will not suffer from this problem.
--
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [SOLUTION] a temporary workaround solution using another language like "python"
[not found] ` <35881.2693202466$1682946783@news.gmane.org>
@ 2023-05-01 13:35 ` Max Nikulin
2023-05-01 19:01 ` Christopher M. Miles
0 siblings, 1 reply; 24+ messages in thread
From: Max Nikulin @ 2023-05-01 13:35 UTC (permalink / raw)
To: emacs-orgmode
On 01/05/2023 20:08, Christopher M. Miles wrote:
>
> I use another language "python" to replace "sh" to play video now. It successes.
>
> :EVAL: src_python{import os; video_file = "枕刀歌/《枕刀歌》SE05 江海阔 歌谣哼唱.mp4"; os.system("mpv \"%s\" " %(video_file))}
>
> It's not as convenient as shell command directly but at least it works.
> Seems the sh inline source block can't be used to play video using "mpv"
> (I also tested other video player commands like "mplayer", "iina" etc).
For interactive application you may try ob-screen. I find its name
confusing.
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: ob-shell sessions will send final echo '...' as input key sequence when previous command reads input interactively
2023-05-01 13:14 ` Ihor Radchenko
@ 2023-05-01 13:41 ` Christopher M. Miles
2023-05-01 14:20 ` Ihor Radchenko
0 siblings, 1 reply; 24+ messages in thread
From: Christopher M. Miles @ 2023-05-01 13:41 UTC (permalink / raw)
To: Ihor Radchenko; +Cc: Christopher M. Miles, Org-mode, Matt
[-- Attachment #1: Type: text/plain, Size: 3153 bytes --]
Ihor Radchenko <yantar92@posteo.net> writes:
> "Christopher M. Miles" <numbchild@gmail.com> writes:
>
>> I might consider to use another language like python instead of sh to
>> execute command to play video to get around this issue. I will update
>> here if I success.
>
> All you need to do is getting rid of :async and :session.
> Just use :results none + "&" at the end of mpv command.
> Non-session blocks will not suffer from this problem.
My first version property "EVAL" inline src block indeed don't using
:async and :session. It can play video file.
But I found it will block [Tab] org-cycle expand headline. I don't want
Emacs to be suspended. So I added :async change.
Now I use python `os.system()` to invoke shell command works fine.
Here is my current version:
(defcustom org-property-eval-keyword "EVAL"
"A property keyword for evaluate code."
:type 'string
:safe #'stringp
:group 'org)
(add-to-list 'org-default-properties org-property-eval-keyword)
(defun org-property-eval-on-cycle-expand (&optional state)
"Evaluate Org inline source block in property value on headline cycle expand."
(when (memq state '(children subtree))
(if-let ((inline-src-block (org-entry-get nil org-property-eval-keyword nil)))
(with-temp-buffer
(insert inline-src-block)
(goto-char (point-min))
(let* ((context (org-element-context))
(lang (org-element-property :language context))
(type (org-element-type context))
(src-block-info (org-babel-get-src-block-info nil context)))
(when (eq type 'inline-src-block)
(org-babel-execute-src-block
nil src-block-info
(pcase lang
("sh" `((:session . ,(make-temp-name " *ob-sh-inline-async (sh) ")) (:async . "yes") (:results . "silent")))
("shell" `((:session . ,(make-temp-name " *ob-sh-inline-async (shell) ")) (:async . "yes") (:results . "silent")))
("bash" `((:session . ,(make-temp-name " *ob-sh-inline-async (bash) ")) (:async . "yes") (:results . "silent")))
("zsh" `((:session . ,(make-temp-name " *ob-sh-inline-async (zsh) ")) (:async . "yes") (:results . "silent")))
("python" `((:session . ,(make-temp-name "ob-python-inline-async ")) (:async . "yes") (:results . "silent")))
(_ '((:results . "none")))))))))))
(add-hook 'org-cycle-hook #'org-property-eval-on-cycle-expand)
(defvar org-property-eval-templates
'("src_sh{mpg123 \"path/to/music.mp3\"}"
"src_python{import os; os.system(\"mpv 'path/to/video.mp4' \")}"))
(org-completing-read-property-construct-function "EVAL" org-property-eval-templates)
(add-to-list 'org-property-set-functions-alist '("EVAL" . org-completing-read-property_eval))
--
[ stardiviner ]
I try to make every word tell the meaning that I want to express without misunderstanding.
Blog: https://stardiviner.github.io/
IRC(libera.chat, freenode): stardiviner, Matrix: stardiviner
GPG: F09F650D7D674819892591401B5DF1C95AE89AC3
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: ob-shell sessions will send final echo '...' as input key sequence when previous command reads input interactively
2023-05-01 13:41 ` Christopher M. Miles
@ 2023-05-01 14:20 ` Ihor Radchenko
2023-05-01 19:06 ` Christopher M. Miles
0 siblings, 1 reply; 24+ messages in thread
From: Ihor Radchenko @ 2023-05-01 14:20 UTC (permalink / raw)
To: Christopher M. Miles; +Cc: Org-mode, Matt
"Christopher M. Miles" <numbchild@gmail.com> writes:
> My first version property "EVAL" inline src block indeed don't using
> :async and :session. It can play video file.
>
> But I found it will block [Tab] org-cycle expand headline. I don't want
> Emacs to be suspended. So I added :async change.
For my use case, I simply use C-c C-a o to open the attachment or put a
file link inside and use C-c C-o on the heading.
--
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [SOLUTION] a temporary workaround solution using another language like "python"
2023-05-01 13:35 ` Max Nikulin
@ 2023-05-01 19:01 ` Christopher M. Miles
2023-05-01 19:16 ` Ihor Radchenko
0 siblings, 1 reply; 24+ messages in thread
From: Christopher M. Miles @ 2023-05-01 19:01 UTC (permalink / raw)
To: Max Nikulin; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 1006 bytes --]
Max Nikulin <manikulin@gmail.com> writes:
> On 01/05/2023 20:08, Christopher M. Miles wrote:
>> I use another language "python" to replace "sh" to play video now. It successes.
>> :EVAL: src_python{import os; video_file = "枕刀歌/《枕刀歌》SE05 江海阔 歌谣哼唱.mp4";
>> os.system("mpv \"%s\" " %(video_file))}
>> It's not as convenient as shell command directly but at least it works.
>> Seems the sh inline source block can't be used to play video using "mpv"
>> (I also tested other video player commands like "mplayer", "iina" etc).
>
> For interactive application you may try ob-screen. I find its name confusing.
I check out ob-screen, it indeed can be used in my situation, thanks for suggestion.
--
[ stardiviner ]
I try to make every word tell the meaning that I want to express without misunderstanding.
Blog: https://stardiviner.github.io/
IRC(libera.chat, freenode): stardiviner, Matrix: stardiviner
GPG: F09F650D7D674819892591401B5DF1C95AE89AC3
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: ob-shell sessions will send final echo '...' as input key sequence when previous command reads input interactively
2023-05-01 14:20 ` Ihor Radchenko
@ 2023-05-01 19:06 ` Christopher M. Miles
0 siblings, 0 replies; 24+ messages in thread
From: Christopher M. Miles @ 2023-05-01 19:06 UTC (permalink / raw)
To: Ihor Radchenko; +Cc: Christopher M. Miles, Org-mode, Matt
[-- Attachment #1: Type: text/plain, Size: 1053 bytes --]
Ihor Radchenko <yantar92@posteo.net> writes:
> "Christopher M. Miles" <numbchild@gmail.com> writes:
>
>> My first version property "EVAL" inline src block indeed don't using
>> :async and :session. It can play video file.
>>
>> But I found it will block [Tab] org-cycle expand headline. I don't want
>> Emacs to be suspended. So I added :async change.
>
> For my use case, I simply use C-c C-a o to open the attachment or put a
> file link inside and use C-c C-o on the heading.
Indeed, Usually, your suggestion keybinding should be enough. I
originally add this hook for auto play background music or video MV etc.
I might think another method to do this auto action. For example auto
find first media file link and auto open it when match one specific condition.
--
[ stardiviner ]
I try to make every word tell the meaning that I want to express without misunderstanding.
Blog: https://stardiviner.github.io/
IRC(libera.chat, freenode): stardiviner, Matrix: stardiviner
GPG: F09F650D7D674819892591401B5DF1C95AE89AC3
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [SOLUTION] a temporary workaround solution using another language like "python"
2023-05-01 19:01 ` Christopher M. Miles
@ 2023-05-01 19:16 ` Ihor Radchenko
2023-05-02 4:17 ` [CLOSED] [ANSWER] " Christopher M. Miles
0 siblings, 1 reply; 24+ messages in thread
From: Ihor Radchenko @ 2023-05-01 19:16 UTC (permalink / raw)
To: numbchild; +Cc: Max Nikulin, emacs-orgmode
"Christopher M. Miles" <numbchild@gmail.com> writes:
> I check out ob-screen, it indeed can be used in my situation, thanks for suggestion.
Also, you can try --no-terminal cmd switch for mpv. It will suppress
terminal interaction, AFAIU.
--
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>
^ permalink raw reply [flat|nested] 24+ messages in thread
* [CLOSED] [ANSWER] Re: a temporary workaround solution using another language like "python"
2023-05-01 19:16 ` Ihor Radchenko
@ 2023-05-02 4:17 ` Christopher M. Miles
0 siblings, 0 replies; 24+ messages in thread
From: Christopher M. Miles @ 2023-05-02 4:17 UTC (permalink / raw)
To: Ihor Radchenko; +Cc: numbchild, Max Nikulin, emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 751 bytes --]
Ihor Radchenko <yantar92@posteo.net> writes:
> "Christopher M. Miles" <numbchild@gmail.com> writes:
>
>> I check out ob-screen, it indeed can be used in my situation, thanks for suggestion.
>
> Also, you can try --no-terminal cmd switch for mpv. It will suppress
> terminal interaction, AFAIU.
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
--
[ stardiviner ]
I try to make every word tell the meaning that I want to express without misunderstanding.
Blog: https://stardiviner.github.io/
IRC(libera.chat, freenode): stardiviner, Matrix: stardiviner
GPG: F09F650D7D674819892591401B5DF1C95AE89AC3
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]
^ permalink raw reply [flat|nested] 24+ messages in thread
* 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-01 11:39 ` 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) Ihor Radchenko
` (2 preceding siblings ...)
[not found] ` <35881.2693202466$1682946783@news.gmane.org>
@ 2023-05-02 20:31 ` Matt
2023-05-03 10:41 ` Ihor Radchenko
3 siblings, 1 reply; 24+ messages in thread
From: Matt @ 2023-05-02 20:31 UTC (permalink / raw)
To: Ihor Radchenko; +Cc: Org-mode
---- 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
^ permalink raw reply [flat|nested] 24+ messages in thread
* 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 20:31 ` 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) Matt
@ 2023-05-03 10:41 ` Ihor Radchenko
2023-05-03 11:01 ` ob-shell sessions will send final echo '...' as input key sequence when previous command reads input interactively Christopher M. Miles
0 siblings, 1 reply; 24+ messages in thread
From: Ihor Radchenko @ 2023-05-03 10:41 UTC (permalink / raw)
To: Matt; +Cc: Org-mode
Matt <matt@excalamus.com> 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 "..."
<now type "m_" while mpv is still running>
<exit mpv>
$ m_ <m_ is echoed in the next prompt>
> 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 <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: ob-shell sessions will send final echo '...' as input key sequence when previous command reads input interactively
2023-05-03 10:41 ` Ihor Radchenko
@ 2023-05-03 11:01 ` Christopher M. Miles
2023-05-03 12:01 ` Ihor Radchenko
0 siblings, 1 reply; 24+ messages in thread
From: Christopher M. Miles @ 2023-05-03 11:01 UTC (permalink / raw)
To: Ihor Radchenko; +Cc: Matt, emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 4075 bytes --]
Ihor Radchenko <yantar92@posteo.net> writes:
> Matt <matt@excalamus.com> 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 "..."
> <now type "m_" while mpv is still running>
> <exit mpv>
> $ m_ <m_ is echoed in the next prompt>
>
Indeed, this explaination give me more clear understanding of the problem.
So currently ob-shell.el is async sending command into session buffer
without waiting for command to be finished.
I checked out the ob-shell.el source code. I suppose this is the core
part of the problem. From intuitive view, session async evaluation
indeed should not wait for command to be finished. But still feel a
little weird.
#+begin_src emacs-lisp
(session ; session evaluation
(if async
(progn
(let ((uuid (org-id-uuid)))
(org-babel-comint-async-register
session
(current-buffer)
"ob_comint_async_shell_\\(.+\\)_\\(.+\\)"
'ob-shell-async-chunk-callback
nil)
(org-babel-comint-async-delete-dangling-and-eval
session
(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))
uuid))
(mapconcat
#'org-babel-sh-strip-weird-long-prompt
(mapcar
#'org-trim
(butlast ; Remove eoe indicator
(org-babel-comint-with-output
(session org-babel-sh-eoe-output t body)
(insert (org-trim body) "\n"
org-babel-sh-eoe-indicator)
(comint-send-input nil t))
;; Remove `org-babel-sh-eoe-indicator' output line.
1))
"\n")))
#+end_src
>> 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.
If this :stdin interesting idea works, maybe other similar ideas will too.🙋
For examples:
- Wrap command "mpv" with a shell function which disable accepting interactive input.
- Setting shell or environment variable in :prolog for source block to preventing interactive input.
Anyway, glad to get more interesting ideas.
--
[ stardiviner ]
I try to make every word tell the meaning that I want to express without misunderstanding.
Blog: https://stardiviner.github.io/
IRC(libera.chat, freenode): stardiviner, Matrix: stardiviner
GPG: F09F650D7D674819892591401B5DF1C95AE89AC3
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: ob-shell sessions will send final echo '...' as input key sequence when previous command reads input interactively
2023-05-03 11:01 ` ob-shell sessions will send final echo '...' as input key sequence when previous command reads input interactively Christopher M. Miles
@ 2023-05-03 12:01 ` Ihor Radchenko
2023-05-03 16:31 ` Christopher M. Miles
0 siblings, 1 reply; 24+ messages in thread
From: Ihor Radchenko @ 2023-05-03 12:01 UTC (permalink / raw)
To: numbchild; +Cc: Matt, emacs-orgmode
"Christopher M. Miles" <numbchild@gmail.com> writes:
> So currently ob-shell.el is async sending command into session buffer
> without waiting for command to be finished.
>
> I checked out the ob-shell.el source code. I suppose this is the core
> part of the problem. From intuitive view, session async evaluation
> indeed should not wait for command to be finished. But still feel a
> little weird.
The core of the problem is in how Emacs comint is sending multiline
input. My earlier example with M-x shell also demonstrates what is
penning. comint.el basically simulates user input verbatim, as if you
typed the whole thing symbol by symbol, including newlines.
And it makes total sense as long as you are actually typing things
interactively in the comint buffer.
ob-shell :session in this case gets a bit weird. On one hand, it
faithfully simulates interactive session. On the other hand, it does not
feel fully interactive from user perspective, as you send a bunch of
commands together within a single source block.
One way to avoid the situations like with mpv could be packing the whole
code block into script and then sending that script to comint session
buffer. But then people who would like to actually switch to that buffer
and work with it manually will get confused about what is going on
there. (see `org-babel-switch-to-session' and
`org-babel-switch-to-session-with-code').
> If this :stdin interesting idea works, maybe other similar ideas will too.🙋
>
> For examples:
>
> - Wrap command "mpv" with a shell function which disable accepting interactive input.
Is there such a function? For all possible POSIX shells?
> - Setting shell or environment variable in :prolog for source block to preventing interactive input.
Again, do you know how to do this?
--
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: ob-shell sessions will send final echo '...' as input key sequence when previous command reads input interactively
2023-05-03 12:01 ` Ihor Radchenko
@ 2023-05-03 16:31 ` Christopher M. Miles
0 siblings, 0 replies; 24+ messages in thread
From: Christopher M. Miles @ 2023-05-03 16:31 UTC (permalink / raw)
To: Ihor Radchenko; +Cc: numbchild, Matt, emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 2379 bytes --]
Ihor Radchenko <yantar92@posteo.net> writes:
> "Christopher M. Miles" <numbchild@gmail.com> writes:
>
>> So currently ob-shell.el is async sending command into session buffer
>> without waiting for command to be finished.
>>
>> I checked out the ob-shell.el source code. I suppose this is the core
>> part of the problem. From intuitive view, session async evaluation
>> indeed should not wait for command to be finished. But still feel a
>> little weird.
>
> The core of the problem is in how Emacs comint is sending multiline
> input. My earlier example with M-x shell also demonstrates what is
> penning. comint.el basically simulates user input verbatim, as if you
> typed the whole thing symbol by symbol, including newlines.
>
> And it makes total sense as long as you are actually typing things
> interactively in the comint buffer.
>
> ob-shell :session in this case gets a bit weird. On one hand, it
> faithfully simulates interactive session. On the other hand, it does not
> feel fully interactive from user perspective, as you send a bunch of
> commands together within a single source block.
>
> One way to avoid the situations like with mpv could be packing the whole
> code block into script and then sending that script to comint session
> buffer. But then people who would like to actually switch to that buffer
> and work with it manually will get confused about what is going on
> there. (see `org-babel-switch-to-session' and
> `org-babel-switch-to-session-with-code').
>> If this :stdin interesting idea works, maybe other similar ideas will too.🙋
>>
>> For examples:
>>
>> - Wrap command "mpv" with a shell function which disable accepting interactive input.
>
> Is there such a function? For all possible POSIX shells?
>
>> - Setting shell or environment variable in :prolog for source block to preventing interactive input.
>
> Again, do you know how to do this?
I tested with bash and wrap mpv into a function. The :prolog way is not
working too. Seems those workaround tries can't get around the
essential problem. I'm too naive....
--
[ stardiviner ]
I try to make every word tell the meaning that I want to express without misunderstanding.
Blog: https://stardiviner.github.io/
IRC(libera.chat, freenode): stardiviner, Matrix: stardiviner
GPG: F09F650D7D674819892591401B5DF1C95AE89AC3
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]
^ permalink raw reply [flat|nested] 24+ messages in thread
end of thread, other threads:[~2023-05-03 16:45 UTC | newest]
Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-30 4:27 [Need Help] Error to evaluate "mpv" command in inline src block stardiviner
2023-04-30 4:46 ` Ruijie Yu via General discussions about Org-mode.
2023-04-30 10:59 ` Christopher M. Miles
2023-04-30 14:52 ` Ihor Radchenko
2023-05-01 3:39 ` Christopher M. Miles
2023-05-01 7:45 ` Ihor Radchenko
2023-05-01 10:46 ` Christopher M. Miles
2023-05-01 11:39 ` 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) Ihor Radchenko
2023-05-01 12:50 ` ob-shell sessions will send final echo '...' as input key sequence when previous command reads input interactively Christopher M. Miles
2023-05-01 13:14 ` Ihor Radchenko
2023-05-01 13:41 ` Christopher M. Miles
2023-05-01 14:20 ` Ihor Radchenko
2023-05-01 19:06 ` Christopher M. Miles
2023-05-01 13:08 ` [SOLUTION] a temporary workaround solution using another language like "python" Christopher M. Miles
[not found] ` <35881.2693202466$1682946783@news.gmane.org>
2023-05-01 13:35 ` Max Nikulin
2023-05-01 19:01 ` Christopher M. Miles
2023-05-01 19:16 ` Ihor Radchenko
2023-05-02 4:17 ` [CLOSED] [ANSWER] " Christopher M. Miles
2023-05-02 20:31 ` 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) Matt
2023-05-03 10:41 ` Ihor Radchenko
2023-05-03 11:01 ` ob-shell sessions will send final echo '...' as input key sequence when previous command reads input interactively Christopher M. Miles
2023-05-03 12:01 ` Ihor Radchenko
2023-05-03 16:31 ` Christopher M. Miles
2023-05-01 10:50 ` [Need Help] Error to evaluate "mpv" command in inline src block Christopher M. Miles
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).