Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Template Name: Produce HTML Timetables
- *
- * @package Transit_Base_Template
- */
- ini_set('display_errors', 1);
- ini_set('display_startup_errors', 1);
- error_reporting(E_ALL);
- //function to see output of PHP trying to execute node.js command
- function liveExecuteCommand($cmd)
- {
- while (@ ob_end_flush()); // end all output buffers if any
- $proc = popen("$cmd 2>&1 ; echo Exit status : $?", 'r');
- $live_output = "";
- $complete_output = "";
- while (!feof($proc))
- {
- $live_output = fread($proc, 4096);
- $complete_output = $complete_output . $live_output;
- echo "$live_output<br />";
- @ flush();
- }
- pclose($proc);
- // get exit status
- preg_match('/[0-9]+$/', $complete_output, $matches);
- // return exit status and intended output
- return array (
- 'exit_status' => intval($matches[0]),
- 'output' => str_replace("Exit status : " . $matches[0], '', $complete_output)
- );
- }
- if ( is_user_logged_in() ) {
- //first, specifying the path to the node.js command with 'export PATH=$PATH:/home/mcedd/bin/'
- //then running the node.js command with this: 'gtfs-to-html --configPath /home/mcedd/public_html/gorgetranslink.com/gtfs-to-html-configs/config.json';
- //this command works succesfully when run from linux shell when in this directory: '/home/mcedd': 'gtfs-to-html --configPath /home/mcedd/public_html/gorgetranslink.com/gtfs-to-html-configs/config.json';
- $command_line = 'export PATH=$PATH:/home/mcedd/bin/; gtfs-to-html --configPath /home/mcedd/gtfs-to-html-configs/config.json';
- $result = liveExecuteCommand($command_line);
- if($result['exit_status'] === 0){
- echo "the command succeeded";
- } else {
- echo "the command did not succeed";
- }
- echo "<pre>";
- print_r($result);
- echo "</pre>";
- }
- else {
- echo "Sorry, you must be a registered user and logged in to view this page.";
- echo "<h3>Login</h3>";
- echo "<a href='/wp-admin/' class='button'>Login</a>";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement