Results 1 to 3 of 3

Thread: List the output of ls /dev/tty* using QProcess

  1. #1
    Join Date
    Jul 2012
    Location
    India
    Posts
    33
    Thanks
    10
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default List the output of ls /dev/tty* using QProcess

    I am trying to list all the pattern of /dev/tty but it is giving the error ls: cannot access /dev/tty*: No such file or directory


    Qt Code:
    1. QProcess* process = new QProcess(this);
    2. QStringList sArgs;
    3. sArgs << "/dev/tty*";
    4. process->start("ls", sArgs);
    5. process->waitForFinished(-1);
    6. qDebug() << process->readAllStandardOutput();
    7. qDebug() << process->readAllStandardError();
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: List the output of ls /dev/tty* using QProcess

    And what is the problem? If the files do not exist or you do not have permission to see them, then they do not exist or you do not have permission. QProcess does not do UNIX shell wildcard expansion like your shell. There is no file called (literally) "/dev/tty*" and that is what ls is reporting. This is not a Qt issue.

    BTW: Qt has classes for interrogating the file system (e.g. QDir, QFileInfo)
    Last edited by ChrisW67; 3rd September 2013 at 07:31.

  3. #3
    Join Date
    Dec 2008
    Location
    France
    Posts
    93
    Thanked 23 Times in 22 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: List the output of ls /dev/tty* using QProcess

    QProcess run a process and not a shell so the * wilcard does not work.
    This will work, but it's ugly
    Qt Code:
    1. QProcess* process = new QProcess();
    2. process->start("sh -c \"ls /dev/tty*\"");
    3. process->waitForFinished(-1);
    4. qDebug() << process->readAllStandardOutput();
    5. qDebug() << process->readAllStandardError();
    To copy to clipboard, switch view to plain text mode 
    This is better :
    Qt Code:
    1. QDir lsDev("/dev/");
    2. lsDev.setNameFilters(QStringList() << "tty*");
    3. qDebug() << lsDev.entryList(QDir::System);
    To copy to clipboard, switch view to plain text mode 

  4. The following user says thank you to nix for this useful post:

    arunkumaraymuo1 (3rd September 2013)

Similar Threads

  1. Replies: 1
    Last Post: 3rd June 2013, 13:11
  2. Cleaned event list of main app, when qprocess finished.
    By alnorte in forum Qt Programming
    Replies: 2
    Last Post: 1st March 2013, 10:53
  3. Replies: 4
    Last Post: 14th June 2012, 23:33
  4. Replies: 1
    Last Post: 23rd April 2011, 17:33
  5. List View with sections for alphabetialy sorted list
    By woodtluk in forum Qt Programming
    Replies: 4
    Last Post: 12th October 2010, 11:50

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.