admin管理员组文章数量:1123433
When attempting to spawn an interactive bash shell from within a Guile script using the system*
function from the ice-9 popen
module, the shell does not behave as expected. Specifically, the standard input and output do not seem to be redirected correctly, making the shell non-interactive and unusable. The bash shell opens but does not accept input or display output, which suggests that there might be an issue with how I/O is being handled in the Guile script. Additional guidance or examples on properly spawning an interactive shell with correct I/O handling in Guile would be greatly appreciated.
(use-modules (ice-9 popen)) ; For system*
;; Function to spawn an interactive bash shell
(define (spawn-shell)
(format #t "Spawning an interactive bash shell...~%")
(system* "bash") ; Spawn a bash shell and wait for it to exit
(format #t "Returning to the REPL.~%"))
;; Example usage
(spawn-shell)
When attempting to spawn an interactive bash shell from within a Guile script using the system*
function from the ice-9 popen
module, the shell does not behave as expected. Specifically, the standard input and output do not seem to be redirected correctly, making the shell non-interactive and unusable. The bash shell opens but does not accept input or display output, which suggests that there might be an issue with how I/O is being handled in the Guile script. Additional guidance or examples on properly spawning an interactive shell with correct I/O handling in Guile would be greatly appreciated.
(use-modules (ice-9 popen)) ; For system*
;; Function to spawn an interactive bash shell
(define (spawn-shell)
(format #t "Spawning an interactive bash shell...~%")
(system* "bash") ; Spawn a bash shell and wait for it to exit
(format #t "Returning to the REPL.~%"))
;; Example usage
(spawn-shell)
Share
Improve this question
asked 15 hours ago
RainbRainb
2,3901 gold badge17 silver badges36 bronze badges
1 Answer
Reset to default 0You can spawn an interactive bash shell from within the Guile REPL by using low-level system calls to fork a new process and execute bash. Here's how you can do it:
(use-modules (ice-9 popen)
(ice-9 rdelim)
(ice-9 match)) ; For match-let
;; Function to spawn an interactive bash shell
(define (spawn-shell)
(format #t "Spawning an interactive bash shell...~%")
(let ((pid (primitive-fork)))
(if (= pid 0)
;; Child process: replace current process with bash
(begin
;; Replace stdin, stdout, and stderr with the current ones
(dup2 0 0) ; stdin
(dup2 1 1) ; stdout
(dup2 2 2) ; stderr
(execlp "bash" "bash") ; Replace current process with bash
(format #t "Failed to spawn bash shell.~%")
(exit 1))
;; Parent process: wait for the child to exit
(begin
(let ((status (waitpid pid)))
(format #t "Returning to the REPL.~%")
status)))))
;; Example usage
(spawn-shell)
本文标签:
版权声明:本文标题:read eval print loop - How to spawn an interactive bash shell in Guile REPL with proper IO redirection? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736569168a1944747.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论