[Box Backup-dev] Exception thrown in bbackupquery when reading form stdin

Mark boxbackup-dev@fluffy.co.uk
Thu, 23 Feb 2006 21:37:54 +0100


When I run bbackupquery everything goes well (logging in etc) up until 
the point that bbackupquery wants to read a commando from stdin.

This is the section of code from bbackupquery where it goes wrong: (It's 
from the bottom of the file)

#else
    // Version for platforms which don't have readline by default
    FdGetLine getLine(fileno(stdin));
    while(!context.Stop())
    {
        printf("query > ");
        fflush(stdout);
       
        std::string command(getLine.GetLine());   <<<<<<<<<< Here it 
goes wrong

        context.DoCommand(command.c_str());
    }
#endif

The problem is that the code _fileno(stdin) returns 0 and because of 
that, ::read(...) doesn't read anything.

FdGetLine.cpp from line no 123:
#ifdef WIN32
            int bytes;

            if (mFileHandle == _fileno(stdin))  <<<<<<<<<<<<< THIS RETURNS 0
            {
                bytes = console_read(mBuffer, sizeof(mBuffer));
            }
            else
            {
                bytes = ::read(mFileHandle, mBuffer,
                    sizeof(mBuffer));
            }
#else // !WIN32
            int bytes = ::read(mFileHandle, mBuffer, sizeof(mBuffer));
#endif // WIN32
           
            // Error?
            if(bytes == -1)
            {
                THROW_EXCEPTION(CommonException, OSFileError)
            }

When I change the code in bbackupquery slightly its run perfectly. I 
changed the code in the while loop a little (the code at the beginning 
of this message) so it looks like:

#else
    // Version for platforms which don't have readline by default
    while(!context.Stop())
    {
        printf("query > ");
        fflush(stdout);
       
        std::string cmd; // NEW
        std::getline(std::cin,cmd,'\n'); // NEW
        context.DoCommand(cmd.c_str()); // NEW
    }
#endif

I don't know of the problem with FdGetLine can be fixed, so it will run 
on Windows XP?
Is there a reason not to use std::getline(..) function?

Mark