PickBASIC / FlashBASIC
%popen() function
.mdThe %popen() function creates a pipe between the calling process and the command to be executed.
Syntax
pointer = (char*)%popen(command, type)
Parameter(s)
| pointer | Stream pointer that 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. |
|
| command | Shell command line. | |
| type | I/O mode. | |
| r | Reading | |
| w | Writing | |
Description
A stream opened by %popen() must be closed by %pclose(). The stream is closed automatically at FlashBASIC program termination.
Example(s)
include dm,bp,includes sysid.inc cfunction unix.builtin char buffer[128] if system(38)<sys$imp> = sys$win then cmd = "dir" end else cmd = "ls -l" end ptr=(char*)%popen(cmd,"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 UNIX command, capturing the result.