Subject: mailing-list for TeXmacs Users
List archive
From : Henri Lesourd <address@hidden>- To: Corey Sweeney <address@hidden>
- Cc: address@hidden
- Subject: Re: [TeXmacs] getting direct access to shell
- Date: Wed, 15 Mar 2006 23:40:51 +0100
Corey Sweeney wrote:
I would like to get a directory listing in my document by running ls through bash. I need to do it though bash, cause I don't really want to do a directory listing, but run a dynamically generated bash command. How would I go about this? I tried guile's open-port, which seems to only give me the ability to send text to bashes input, but not read bashes output. (i think it should allow both with the OPEN_BOTH switch, but I only get one write port. I tried that "multi-value stuff" to see if there was a seperate read port and that didn't seem to be it either) open-port* would work as it takes args for the program, and i could pass my input as a argument, but open-port* appears to have started in a later version of guile then we are using. It dosn't have to be though scheme. I just want the ability to type a bash command and have the result display in my document, (without seeing the command itself and other stuff (as happens in shell "sessions")). Hopefully something I can potentially later macro-ize or abstract.(use-modules (ice-9 popen))
(define (unix-command cmd)
(let* ((p (open-input-pipe cmd))
(out (read-delimited "" p)))
(if (eof-object? out) "" (string-split out #\newline))))
(Warning : the (use-modules) is *mandatory*). Then, under
guile, you could do :
[[
guile> (unix-command "ls /")
("bin" "boot" "cdrom" "dev" "etc" "home" "lib" "media" "mnt" "opt" "proc" "project" "root" "sbin" "share" "srv" "sys" "tmp" "usr" "var" "windows" "")
guile> (unix-command "ls -l /")
("total 204" "drwxr-xr-x 2 root root 2920 2005-04-12 16:54 bin" "drwxr-xr-x 4 root root 1024 2005-10-07 16:19 boot" "drwxr-xr-x 2 root root 0 2006-02-22 11:33 cdrom" "drwxr-xr-x 34 root root 179984 2006-03-01 16:54 dev" "drwxr-xr-x 75 root root 7192 2006-03-15 22:52 etc" "drwxr-xr-x 3 root root 0 2006-02-22 11:33 home" "drwxr-xr-x 12 root root 3288 2005-04-12 18:10 lib" "drwxr-xr-x 7 root root 216 2006-03-01 16:31 media" "drwxr-xr-x 2 root root 48 2004-10-04 17:24 mnt" "drwxr-xr-x 10 root root 256 2005-06-08 14:41 opt" "dr-xr-xr-x 82 root root 0 2006-02-22 12:32 proc" "drwxr-xr-x 5 root root 0 2006-02-22 11:33 project" "drwx------ 22 root root 856 2005-11-21 20:10 root" "drwxr-xr-x 3 root root 7696 2005-06-16 05:26 sbin" "drwxr-xr-x 2 root root 0 2006-02-22 11:33 share" "drwxr-xr-x 4 root root 96 2005-04-12 15:37 srv" "drwxr-xr-x 9 root root 0 2006-02-22 12:32 sys" "drwxrwxrwt 43 root root 7096 2006-03-15 22:45 tmp" "drwxr-xr-x 14 root root 376 2005-04-12 17:01 usr" "drwxr-xr-x 16 root root 392 2005-04-12 16:52 var" "drwxr-xr-x 3 root root 72 2005-10-07 18:02 windows" "")
guile> _
]]
Note: if you want to get the output as a string, just
strip out the (string-split) in the code above.
Then what remains to do is to encapsulate the output of (unix-command)
into a TeXmacs macro, like this :
[[
(tm-define (tm-unix-command cmd)
(:secure #t)
(unix-command cmd))
]]
and then, in a stylesheet :
[[
<assign|unix-command|<macro|cmd|<extern|tm-unix-command|<arg|cmd>>>>
]]
Thus, you should be able to type <unix-command|ls -l> under
TeXmacs, and then you should get the raw output above. What
remains to be done is improving the presentation, for example
generating '(document "bin" "boot" "cdrom" ...), or more
sophisticated presentations using a table, or whatever
you want.
Best, Henri
- getting direct access to shell, Corey Sweeney, 03/15/2006
- Re: [TeXmacs] getting direct access to shell, Henri Lesourd, 03/15/2006
Archive powered by MHonArc 2.6.19.