popen() function in PHP


The popen() function opens a pipe. It can be used with fgets(), fgetss(), and fwrite(). The file pointer initiated by the popen() function must be closed with pclose().

Syntax

popen(command, mode)

Parameters

  • command − Set the command to be executed

  • mode − Set the mode, such as “r”, “w”, etc.

Return

The popen() function returns TRUE on success. It returns FALSE if an error occurs.

Example

<?php
   // opening a pipe
   $file_pointer = popen("/bin/ls", "r");
   pclose($file_pointer);
?>

Output

TRUE

Let us see another example.

Example

<?php
   // opening a pipe
   $file_pointer = popen("/executable/installer.exe", "r");
   pclose($file_pointer);
?>

Output

TRUE

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 24-Jun-2020

416 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements