open replacement and p for pipes

3 views
Skip to first unread message

Aule

unread,
Dec 23, 2009, 10:42:01 AM12/23/09
to objecticon
Could someone add a note on this difference with Icon?

Is Windows 7 now so very Posix-like?

r.parlett

unread,
Dec 25, 2009, 7:05:28 PM12/25/09
to objecticon
Unfortunately the io.open procedure doesn't support the "p" option.
However, there is equivalent (and more flexible) functionality in the
io.ProgStream class, which has static methods open_read and open_write
which open pipes to external programs for reading and writing
respectively. For example :-

x := ProgStream.open_read("ls", ["-l"]) | stop(&why)
while write(x.read())

lists the current directory. Note that the second argument is a list
of the arguments to the command. If you want to have the arguments
parsed from a single string, or do wildcard expansion, you can run "sh
-c <command>" :-

x := ProgStream.open_read("sh", ["-c", "ls -l *.icn"]) | stop(&why)

Both open_read and open_write let you set the environment of the
external program and also redirect its input (or output as the case
may be) -see the autogenerated docs for more details.

I have no idea how well this would work under Windows (if at all).
These functions are based on fork, dup and exec, so they are very much
unix functions really.

Hope this helps.

Regards
R

Reply all
Reply to author
Forward
0 new messages