Page 1 of 1

CLI closes without error after inputting text with sdtin

Posted: Sat Jun 06, 2009 10:14 pm
by XaeroDegreaz
Hi, thanks for taking the time to check out this post.

To make a long story short, I'm taking input from the command line, and using that input to make a decision, and then load another class based on that decision. For some reason it keeps exiting, without loading the class and without error:

This is the first part of the code:

Code: Select all

 
$xml = simplexml_load_file("Config.xml");
 
$em = new ExtensionManager();
 
$extension = $em->ScanExtensions((string)$xml->default_extension);
 
echo("This text will not appear");
 
//# This seems to call, but it exits immediately afterwards and it SHOULDN'T because inside is an infinite loop.
$e = new $extension();
 
Here is the ScanExtension method:

Code: Select all

 
public function ScanExtensions($defaultExtension) {
    Logger::log(__CLASS__, "Listing valid extensions...");
        
    if ($handle = opendir('./Extensions')) {
 
        echo("*********************************************\n");
        $i = 1;
        $list = array();
        while (false !== ($file = readdir($handle))) {
 
            if ($file != "." && $file != ".." && is_dir("./Extensions/$file")) {
 
                if(file_exists("./Extensions/$file/$file.php")) {
                    echo("[$i]\t$file\n");
                    $list[] = $file;
                    $i++;
                }
 
            }
 
        }
        closedir($handle);
        echo("*********************************************\n");
    }
 
    $out = fopen("php://stdout", "w");
    $in = fopen("php://stdin", "r");
 
    fwrite($out, "Which project should I launch? [blank = $defaultExtension]: ");
    $ProjectName = trim(fgets($in));
        
    fclose($out);
    fclose($in);
        
    if($ProjectName > 0) {
        Logger::log(__CLASS__, "Loading extension ".$list[$ProjectName-1].".");
        //sleep(3);
        $ext =  $list[$ProjectName-1];
    }else {
        Logger::log(__CLASS__, "Loading default extension $defaultExtension.");
        //sleep(3);
        $ext = $defaultExtension;
    }
 
    return $ext;
 
}
 
This method goes through everything fine. It accepts user input and seems to return the correct string stored in $ext (I know it is working because I purposely made some errors in the class it should call, and it appears in my log file)

It just simply exits without any errors at all! I have error_reporting set to E_ALL. There is nothing wrong with the class file that gets called, because I can launch it just fine by commenting out the call to the ScanExtension method, and typing $e = new Example() in the first block of outlined code above.

I'm not sure what's going on. I have tried taking the ScanExtension code from the method and just placing it beneath the first code block outlined above, and I get the same results.

Any help at all would be greatly appreciated!

Re: CLI closes without error after inputting text with sdtin

Posted: Sat Jun 06, 2009 11:56 pm
by requinix
- So I guess you have some kind of autoloader in place? Are you sure it knows to look in Extensions/class/class.php?
- If you try having it use the default class (ie, type nothing at the prompt) does that work?

Generic advice: litter your code with echos and follow along in the output until the echos stop working.