/** * Checks if the given virtual command line interface exists by id. * * @param $id The id used to create the original virtual command line interface. * * @return bool Returns true if the given $id exists otherwise false. */ static function has_cli($id) { $cli_list = VCLIManager::cli_list(); $list = []; foreach ($cli_list as $c) { $c = new GString($c); array_push($list, $c->delRightMost(chr(9))->__toString()); } return in_array($id, $list); }
*/ require '../vendor/autoload.php'; include '../src/Steveorevo/VirtualCLI/VirtualCLI.php'; use Steveorevo\VirtualCLI\VCLIManager; use Steveorevo\VirtualCLI\VirtualCLI; // Create a new virtual command line interface named "test" (or continue accessing an existing one of that name) VCLIManager::init(); $myVCLI = new VirtualCLI("test"); // Queue typing 'ls' or 'dir' (Windows) on the command line if (VCLIManager::$platform === 'win32') { $myVCLI->add_command('dir'); } else { $myVCLI->add_command('ls'); } // List any existing consoles var_dump(VCLIManager::cli_list(2)); // Start processing commands in queue $myVCLI->start(); // Wait until the queue is done while (false === $myVCLI->is_done()) { usleep(1000); // Wait a second } // Echo out the console history echo $myVCLI->get_results(); // List any existing consoles var_dump(VCLIManager::cli_list(2)); // Close the terminal $myVCLI->close(); // Shutdown the VCLI daemon VCLIManager::shutdown();