Author Topic: Open Command  (Read 1942 times)

ashikase

  • Sr. Member
  • ****
  • Posts: 280
    • View Profile
    • http://
Open Command
« on: March 04, 2005, 09:24:04 am »
I'm looking for a way to implement OS X/BSD's "open" command, which allows you to open a file with its associated application from the command line.

For example, typing "open file.html" would open the file with Opera (or whatever app is associated with html).

I whipped up the following, which works, but I'm hoping for something better:
Code: [Select]
#include
#include
#include

int main(int argc, char * argv[])
{
   QPEApplication a(argc, argv);

   if ( argc != 2 ) {
      qDebug("Usage: %s filename", argv[0]);
      return -1;
   }

   QFileInfo file(argv[1]);
   if ( !file.exists() ) {
      qDebug("File does not exist!");
      return -1;
   }

   DocLnk fileLnk(file.absFilePath());
   if ( fileLnk.exec().isNull() ) {
      qDebug("No application is associated with this file type!");
      return -1;
   }

   fileLnk.execute();

   return 0;
}
The problem with the above program is that calling DocLnk seems to require that a QPEApplication is created, even if it's not used. When the program is run, it spits out the extra "Display size = ..." line.

Are there already any tools/commands that can do this? Am I perhaps overlooking something obvious?

Any input would be appreciated.

- ashikase
- anpachi, gifu, japan
SL-C3100 & SL-C760