basic.%popen

C Function/BASIC Program, Releases: AP/Unix

Creates pipe between calling process and command.

Syntax

pointer=(char*)%popen(command, type )

Description

creates a pipe between the calling process and the command to be executed.

'command' Shell command line.

'type' I/O mode, either 'r' for reading or 'w' for writing.

'pointer' Stream pointer which directs a write to the standard input of the command if the I/O mode is 'w', and reads from the standard output of the command if the type is 'r'.

A stream opened by '%popen()' must be closed by 'pclose()'. The stream is closed automatically at Pick/BASIC program termination.

Example

char buffer[128]
ptr=(char*)%popen('ls -l','r')
if ptr=0 then crt 'error'; stop
loop
n=(char*)%fgets(buffer,128,(char*)ptr)
while n#0 do
print field(buffer,char(0),1)
repeat
%pclose((char*)ptr)
This example executes a C command, capturing the result.

See Also

Command Name Type Description
basic.cfunc Definition can be called from a Pick/BASIC program or subroutine in AP/DOS and AP/Unix implementations using a syntax similar to that of normal C.
basic.%pclose C Function Closes a stream.
basic.%fgets C Function Reads a C string from a stream.
basic.%fputs C Function Writes a string on a stream.
basic.execute.unix Statement Executes Unix command from Pick/BASIC.
basic.cfunction Definition Declare a list of C functions.

User Comments

What do you think?

Share your experience or ask a question by using the form below.

Login to leave your comments.