exec_group/3 and redirecting its output to a file

From: Sebastian Sardina <ssardina_at_cs.toronto.edu>
Date: Fri 01 Nov 2002 04:05:27 AM GMT
Message-Id: <1036123527.6986.14.camel@ssardina.com.ar>
I have a problem that may be very simple for some people. I have tried
some solutions without success.

I want to execute in Prolog a Unix command, say 'ls', and send its
output to a file. I have to do it with exec_group (that is, no sh system
or others.)

1) My first bet was:

[eclipse 10]: exec_group("ls > file.txt",[],P).

P = 7701
Yes (0.00s cpu)
[eclipse 11]: ls: >: No such file or directory
ls: file.txt: No such file or directory


it seems that does not work and it may have trouble with '>'


2) My other "solution" was to open a file, and attach it to the output
stream of exec_group:

[eclipse 11]: open('file.txt',write,myfile),
exec_group("ls",[null,myfile],P), 

P = 7706
Yes (0.00s cpu)


This didn't not work either.! Even after doing a wait(P,X) and
close(myfile), nothing is printed to the file!!

I can't figure out why these two methods do not work and how should I do
it without changing to other predicates (like sh, systems) and without
using any scripts outside Prolog. I know there has to be a simple way of
doing this.

Thanks in advance

Sebastian
Received on Fri Nov 01 04:08:38 2002

This archive was generated by hypermail 2.1.8 : Wed 16 Nov 2005 06:07:17 PM GMT GMT