Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2009-11

using popen() and assign/reset

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Marc Santhoff

Hello,

I'm trying to get unix.popen() running. The RTL.pdf says the file opened with popen (stdin for reading here) has to be reset or rewritten. The example does not do anything like that.

The other part is the question whether the file has to be assign()'ed befor or not.

var
  f: text;
  s: ansistring;
begin
  s := '';
  popen(f, '/usr/bin/w', 'r');
  reset(f);
  readln(f, s);
  close(f);
  writeln(s);
end;

Using it that way does not work, it prints an empty string. Leaving out reset does the same.

Running the command on the command line does actually print out something (one line).

What's wrong here?

Marc Santhoff
Marco van de Voort
to Marc Santhoff

In our previous episode, Marc Santhoff said:

I'm trying to get unix.popen() running. The RTL.pdf says the file opened with popen (stdin for reading here) has to be reset or rewritten. The example does not do anything like that.
Apparantly that is false;
uses unix;
var
  f: text;
  s: ansistring;
begin
  s := '';
  popen(f, '/usr/bin/w', 'r');
//  reset(f);
  while not eof(f) do
  begin
    readln(f, s);
    writeln(s);
  end;
  close(f);
end.

works fine. Please file a bug against the documentation.