mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-12 13:06:18 +02:00
+ Added example for iostreams and tprocess
This commit is contained in:
parent
1b1f3d5850
commit
8d3f033046
@ -1,5 +1,5 @@
|
|||||||
#
|
#
|
||||||
# Makefile generated by fpcmake v0.99.13 [2000/02/09]
|
# Makefile generated by fpcmake v0.99.13 [2000/02/08]
|
||||||
#
|
#
|
||||||
|
|
||||||
defaultrule: all
|
defaultrule: all
|
||||||
@ -184,7 +184,7 @@ endif
|
|||||||
|
|
||||||
# Targets
|
# Targets
|
||||||
|
|
||||||
override EXEOBJECTS+=stringl dparser fstream mstream list threads testrtf cfgtest xmldump htdump testcgi tidea b64test b64test2 b64enc b64dec restest testz testz2
|
override EXEOBJECTS+=stringl dparser fstream mstream list threads testrtf cfgtest xmldump htdump testcgi tidea b64test b64test2 b64enc b64dec restest testz testz2 istream doecho testproc
|
||||||
ifeq ($(OS_TARGET),win32)
|
ifeq ($(OS_TARGET),win32)
|
||||||
override EXEOBJECTS+=showver
|
override EXEOBJECTS+=showver
|
||||||
endif
|
endif
|
||||||
@ -793,16 +793,6 @@ override FPCOPT+=-Xs -OG2p3 -n
|
|||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# Strip
|
|
||||||
ifdef STRIP
|
|
||||||
override FPCOPT+=-Xs
|
|
||||||
endif
|
|
||||||
|
|
||||||
# Optimizer
|
|
||||||
ifdef OPTIMIZE
|
|
||||||
override FPCOPT+=-OG2p3
|
|
||||||
endif
|
|
||||||
|
|
||||||
# Verbose settings (warning,note,info)
|
# Verbose settings (warning,note,info)
|
||||||
ifdef VERBOSE
|
ifdef VERBOSE
|
||||||
override FPCOPT+=-vwni
|
override FPCOPT+=-vwni
|
||||||
|
@ -5,7 +5,8 @@
|
|||||||
[targets]
|
[targets]
|
||||||
programs=stringl dparser fstream mstream list threads testrtf \
|
programs=stringl dparser fstream mstream list threads testrtf \
|
||||||
cfgtest xmldump htdump testcgi tidea \
|
cfgtest xmldump htdump testcgi tidea \
|
||||||
b64test b64test2 b64enc b64dec restest testz testz2
|
b64test b64test2 b64enc b64dec restest testz testz2 \
|
||||||
|
istream doecho testproc
|
||||||
programs_win32=showver
|
programs_win32=showver
|
||||||
|
|
||||||
rst=restest
|
rst=restest
|
||||||
|
@ -34,3 +34,6 @@ b64enc.pp base64-encodes StdIn to StdOut (SG)
|
|||||||
b64dec.pp base64-decodes StdIn to StdOut (SG)
|
b64dec.pp base64-decodes StdIn to StdOut (SG)
|
||||||
restest.pp test program for resourcestrings with GNU gettext. (MVC)
|
restest.pp test program for resourcestrings with GNU gettext. (MVC)
|
||||||
(see also intl subdirectory)
|
(see also intl subdirectory)
|
||||||
|
istream.pp testprogram for input/output streams.
|
||||||
|
testproc.pp testprogram for TProcess object. Needs doecho to be compiled
|
||||||
|
also.
|
||||||
|
10
fcl/tests/doecho.pp
Normal file
10
fcl/tests/doecho.pp
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
program doecho;
|
||||||
|
|
||||||
|
uses sysutils;
|
||||||
|
|
||||||
|
var r : integer;
|
||||||
|
|
||||||
|
begin
|
||||||
|
for r := 1 to 25 do
|
||||||
|
writeln ('Line : ', inttostr (r));
|
||||||
|
end.
|
43
fcl/tests/istream.pp
Normal file
43
fcl/tests/istream.pp
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
Program TestStream;
|
||||||
|
|
||||||
|
{
|
||||||
|
When testing, remember to send something through standard input !!
|
||||||
|
}
|
||||||
|
|
||||||
|
uses sysutils,classes,iostream;
|
||||||
|
|
||||||
|
Var Stream : TIOStream;
|
||||||
|
S,T : String;
|
||||||
|
i : longint;
|
||||||
|
SS : ShortString;
|
||||||
|
|
||||||
|
begin
|
||||||
|
S:='ABCDEFGHIJKLMNOPQRSTUVWXYZ %d'#10;
|
||||||
|
T:=S;
|
||||||
|
Writeln ('Creating output stream.');
|
||||||
|
Stream:=TIOStream.Create(iosOutPut);
|
||||||
|
For I:=1 to 10 do
|
||||||
|
begin
|
||||||
|
S:=Format(T,[I]);
|
||||||
|
Stream.WriteBuffer (S[1],Length(S));
|
||||||
|
end;
|
||||||
|
Stream.Free;
|
||||||
|
Writeln ('Creating error stream.');
|
||||||
|
Stream:=TIOStream.Create(iosError);
|
||||||
|
For I:=1 to 10 do
|
||||||
|
begin
|
||||||
|
S:=Format(T,[I]);
|
||||||
|
Stream.WriteBuffer (S[1],Length(S));
|
||||||
|
end;
|
||||||
|
Stream.Free;
|
||||||
|
Writeln ('Creating input stream');
|
||||||
|
Stream:=TIOStream.Create(iosInput);
|
||||||
|
SS:='aha';
|
||||||
|
While Length(SS)>0 do
|
||||||
|
begin
|
||||||
|
SetLength(SS,Stream.Read(SS[1],255));
|
||||||
|
Write(SS);
|
||||||
|
end;
|
||||||
|
Writeln ('Read ',Stream.Position,' bytes.');
|
||||||
|
Stream.Free;
|
||||||
|
end.
|
28
fcl/tests/testproc.pp
Normal file
28
fcl/tests/testproc.pp
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
program testproc;
|
||||||
|
|
||||||
|
uses classes,process;
|
||||||
|
|
||||||
|
Const BufSize = 1024;
|
||||||
|
|
||||||
|
{$ifdef linux}
|
||||||
|
TheProgram = 'doecho';
|
||||||
|
{$else}
|
||||||
|
TheProgram = 'doecho.exe';
|
||||||
|
{$endif}
|
||||||
|
|
||||||
|
|
||||||
|
Var S : TProcess;
|
||||||
|
Buf : Array[1..BUFSIZE] of char;
|
||||||
|
I,Count : longint;
|
||||||
|
|
||||||
|
begin
|
||||||
|
S:=TProcess.Create(theprogram,[poExecuteOnCreate,poUsePipes]);
|
||||||
|
Repeat
|
||||||
|
Count:=s.output.read(buf,BufSize);
|
||||||
|
// reverse print for fun.
|
||||||
|
For I:=Count downto 1 do
|
||||||
|
write(buf[i]);
|
||||||
|
until Count<BufSize;
|
||||||
|
writeln;
|
||||||
|
S.Free;
|
||||||
|
end.
|
Loading…
Reference in New Issue
Block a user