Advertisement
Guest User

Untitled

a guest
Aug 5th, 2019
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.07 KB | None | 0 0
  1. <?php
  2. /**
  3. * Template Name: Produce HTML Timetables
  4. *
  5. * @package Transit_Base_Template
  6. */
  7.  
  8. ini_set('display_errors', 1);
  9. ini_set('display_startup_errors', 1);
  10. error_reporting(E_ALL);
  11.  
  12. //function to see output of PHP trying to execute node.js command
  13. function liveExecuteCommand($cmd)
  14.         {
  15.        
  16.             while (@ ob_end_flush()); // end all output buffers if any
  17.        
  18.             $proc = popen("$cmd 2>&1 ; echo Exit status : $?", 'r');
  19.        
  20.             $live_output     = "";
  21.             $complete_output = "";
  22.        
  23.             while (!feof($proc))
  24.             {
  25.                 $live_output     = fread($proc, 4096);
  26.                 $complete_output = $complete_output . $live_output;
  27.                 echo "$live_output<br />";
  28.                 @ flush();
  29.             }
  30.        
  31.             pclose($proc);
  32.        
  33.             // get exit status
  34.             preg_match('/[0-9]+$/', $complete_output, $matches);
  35.        
  36.             // return exit status and intended output
  37.             return array (
  38.                             'exit_status'  => intval($matches[0]),
  39.                             'output'       => str_replace("Exit status : " . $matches[0], '', $complete_output)
  40.                          );
  41.         }
  42.        
  43.         if ( is_user_logged_in() ) {
  44.        
  45.        
  46.        
  47.             //first, specifying the path to the node.js command with 'export PATH=$PATH:/home/mcedd/bin/'
  48.             //then running the node.js command with this: 'gtfs-to-html --configPath /home/mcedd/public_html/gorgetranslink.com/gtfs-to-html-configs/config.json';
  49.             //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';
  50.             $command_line = 'export PATH=$PATH:/home/mcedd/bin/; gtfs-to-html --configPath /home/mcedd/gtfs-to-html-configs/config.json';
  51.            
  52.            
  53.            
  54.             $result = liveExecuteCommand($command_line);
  55.             if($result['exit_status'] === 0){
  56.                echo "the command succeeded";
  57.             } else {
  58.                 echo "the command did not succeed";
  59.             }
  60.            
  61.             echo "<pre>";
  62.             print_r($result);
  63.             echo "</pre>";
  64.        
  65.          }
  66.        else {
  67.            echo "Sorry, you must be a registered user and logged in to view this page.";
  68.            echo "<h3>Login</h3>";
  69.            echo "<a href='/wp-admin/' class='button'>Login</a>";
  70.        }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement