|
From: fungsin.lui on 7 Jun 2006 12:22 (My apologize for posting sbcl specific question here. I tried sbcl-devel(a)lists.sourceforge.net first but my message never reach the mailing list...) Hi, Can anyone explain how I can run a shell subprocess within sbcl repl? I tried all the combination of the key parameters :input :output and :pty but it doesn't seem to work. I don't know enough of sbcl's internal to figure out what's missing. Attached are some sessions with sbcl and acl80 (which can run sh without any problem) under linux 2.6. Thanks in advance, fungsin. vmware(a)vmware-bavm:~$ sbcl This is SBCL 0.9.11, an implementation of ANSI Common Lisp. * (run-program "/usr/bin/who" nil :input t :output t :wait t :pty nil) vmware :0 Jun 6 06:09 vmware pts/2 Jun 6 06:21 (:pts/0:S.0) vmware pts/3 Jun 6 11:08 (:pts/0: S.1) vmware pts/4 Jun 6 11:11 (:pts/0:S.2) vmware pts/5 Jun 6 11:23 (:pts/0:S.3) #<SB-IMPL::PROCESS 6986 :EXITED> * (run-program "/bin/sh" nil :input t :output t :wait t :pty nil) Ctrl-\ Quit * (run-program "/bin/sh" nil :input t :output t :wait t :pty t) Ctrl-\ Quit ;; ACL 80 CL-USER(2): (run-shell-command "who") vmware :0 Jun 6 06:09 vmware pts/2 Jun 6 06:21 (:pts/0:S.0) vmware pts/3 Jun 6 11:08 (:pts/0:S.1) vmware pts/4 Jun 6 11:11 (:pts/0: S.2) 0 CL-USER(3): (shell "/bin/sh") sh-3.00$ ls gconfd-vmware keyring-cgtpMG orbit-vmware ssh-PyhjPx6302 sh-3.00$ exit exit 0 CL-USER(4):
From: GP lisper on 7 Jun 2006 17:07 On 7 Jun 2006 09:22:45 -0700, <fungsin.lui(a)gmail.com> wrote: > > Can anyone explain how I can run a shell subprocess within sbcl repl? It appears that you are running the program, and expecting the output. You need something similar to: (defun read-from-ngrep-save-to-file () "real-time processing, saved in /tmp" (with-open-stream (quotes (ext:process-output (ext:run-program "/usr/bin/ngrep" '("-qltW" "none" "src" "63.77.167.140" "and" "port" "443") :output :stream :wait nil :error nil))) (with-open-file (*file* (pathname "/tmp/n100-today") :direction :output :if-exists :overwrite :if-does-not-exist :create) (when quotes (let ((first-line (read-line quotes nil))) (header first-line)) (loop for line = (read-line quotes nil) while line do ..... which is some old cmucl cells code that runs a filter and leaves a trace in /tmp The process-output needs to wrap the run-program, the cmucl docs might be of some use. -- Reply-To email is ignored. -- Posted via a free Usenet account from http://www.teranews.com
From: fungsin.lui on 7 Jun 2006 18:14 GP lisper wrote: > > It appears that you are running the program, and expecting the > output. Thanks for the response. Maybe I'm not so clear in my original post. What I want to do is spawn a shell from the repl. Do whatever I want with the shell. When I quit the shell, I'll be back at the repl. Running an external program to completion (like who or ngrep) is not a problem. As seen from my post I can do this easily with sbcl and ACL. But I can't spawn an interactive shell with sbcl's (run-program "/bin/sh" nil :input t :output t :wait t :pty t) I must be missing something very obvious... TIA, fungsin ;; ---------------------------- ;; ACL 8.0 ;; spawn a shell CL-USER(3): (shell "/bin/sh") ;; type whatever commands sh-3.00$ ls gconfd-vmware keyring-cgtpMG orbit-vmware ssh-PyhjPx6302 ;; done with shell sh-3.00$ exit exit 0 ;; back to repl CL-USER(4): ;; ---------------------------- ;; sbcl * (run-program "/bin/sh" nil :input t :output t :wait t :pty nil) ;; nothing happens. Ctrl-\ Quit * (run-program "/bin/sh" nil :input t :output t :wait t :pty t) ;; nothing happens. Ctrl-\ Quit
From: GP lisper on 7 Jun 2006 19:36 On 7 Jun 2006 15:14:21 -0700, <fungsin.lui(a)gmail.com> wrote: > > What I want to do is spawn a shell from the repl. Do whatever I want > with the shell. > When I quit the shell, I'll be back at the repl. you mean that you want to suspend the lisp program, a la ^z > Running an external program to completion (like who or ngrep) is not a > problem. As seen from my post I can do this easily with sbcl and ACL. > > But I can't spawn an interactive shell with sbcl's (run-program > "/bin/sh" nil :input t :output t :wait t :pty t) > > I must be missing something very obvious... where did the input/output streams go? what did you expect them to do? the supplied code treated the output stream rather explicitly on a windowing OS, simply popup a window: (ext:run-program "xterm" nil :wait nil) on a non-windowing OS, use 'screen' or login again, there are dozens of non-lisp solutions > CL-USER(3): (shell "/bin/sh") the obvious answer is to investigate ACL's "shell" sourcecode. -- Reply-To email is ignored. -- Posted via a free Usenet account from http://www.teranews.com
From: Juho Snellman on 7 Jun 2006 20:54
fungsin.lui(a)gmail.com <fungsin.lui(a)gmail.com> wrote: > (My apologize for posting sbcl specific question here. I tried > sbcl-devel(a)lists.sourceforge.net > first but my message never reach the mailing list...) The sourceforge mailing lists have been a bit erratic for the last week or so. > Attached are some sessions with sbcl and acl80 (which can run sh > without any problem) under linux 2.6. [...] > * (run-program "/bin/sh" nil :input t :output t :wait t :pty nil) In principle this looks like it should work, and does indeed work on a non-Linux system or (rather bizarrely) on Linux when a "strace -ff" has been attached to the sbcl process. Based on a little bit of poking, it looks like it's some sort of interaction with the shell's job control and the tty-backed fds that end up getting used for stdin / stdout. You could roll your own from fork() and exec*(). e.g. (require :sb-posix) (define-alien-routine "execl" int (path c-string) (arg0 c-string) (arg1 c-string)) (defun run-shell () (let ((pid (sb-posix:fork))) (if (= pid 0) (execl "/bin/sh" "/bin/sh" nil) (let ((status (make-array 1 :element-type '(signed-byte 32)))) (sb-posix:waitpid pid 0 status))))) [ Not really a proper implementation, more of a skeleton ] -- Juho Snellman |