Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. why QProcess not show output of ls /dev/sd* command ?
Forum Updated to NodeBB v4.3 + New Features

why QProcess not show output of ls /dev/sd* command ?

Scheduled Pinned Locked Moved Solved General and Desktop
18 Posts 4 Posters 1.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J jsulm
    14 Dec 2022, 11:57

    @Qt-embedded-developer said in why QProcess not show output of ls /dev/sd* command ?:

    i think its not relative path this is absolute path

    How is ls an absolute path?!
    On my Ubuntu machine the absolute path to ls is /usr/bin/ls

    I'm wondering why you need QProcess for such a task at all? You can simply use https://doc.qt.io/qt-6/qdir.html

    Q Offline
    Q Offline
    Qt embedded developer
    wrote on 14 Dec 2022, 12:14 last edited by
    #8

    @jsulm means i just need to check there is file name start with sd is there on not int /dev directory

    J 1 Reply Last reply 14 Dec 2022, 12:17
    0
    • J JonB
      14 Dec 2022, 11:52

      @Qt-embedded-developer
      Because your /dev/sd* has a * wildcard in it. ls (or any other Linux command) does not expand wildcards. Only a shell expands wildcards! If you want to do it this way you will need:

       Command = "/bin/sh";
      
      args << "-c" << "ls /dev/sd*";
      

      Note that running a command to expand a filepath like this is not "efficient". You could do the work from, say, Qt QDir on /dev and look through the child filenames yourself to see which start with sd. Or QFileInfoList QDir::entryInfoList(const QStringList &nameFilters, QDir::Filters filters = NoFilter, QDir::SortFlags sort = NoSort) const could be used to do the wildcard matching. This would also be a lot cleaner than your code trying to parse ls's output.

      Q Offline
      Q Offline
      Qt embedded developer
      wrote on 14 Dec 2022, 12:16 last edited by
      #9

      @JonB said in why QProcess not show output of ls /dev/sd* command ?:

      QFileInfoList QDir::entryInfoList(const QStringList &nameFilters, QDir::Filters filters = NoFilter, QDir::SortFlags sort = NoSort) const

      as per my case what i need to write in above ?

      J 1 Reply Last reply 14 Dec 2022, 12:17
      0
      • Q Qt embedded developer
        14 Dec 2022, 12:14

        @jsulm means i just need to check there is file name start with sd is there on not int /dev directory

        J Offline
        J Offline
        jsulm
        Lifetime Qt Champion
        wrote on 14 Dec 2022, 12:17 last edited by
        #10

        @Qt-embedded-developer Yes, get entries in /dev folder using QDir::entryInfoList and filter all entries starting with sd (you can pass file name filter directly to QDir::entryInfoList).

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • Q Qt embedded developer
          14 Dec 2022, 12:16

          @JonB said in why QProcess not show output of ls /dev/sd* command ?:

          QFileInfoList QDir::entryInfoList(const QStringList &nameFilters, QDir::Filters filters = NoFilter, QDir::SortFlags sort = NoSort) const

          as per my case what i need to write in above ?

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 14 Dec 2022, 12:17 last edited by
          #11

          @Qt-embedded-developer said in why QProcess not show output of ls /dev/sd* command ?:

          as per my case what i need to write in above ?

          What exactly is not clear?

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          Q 1 Reply Last reply 14 Dec 2022, 12:19
          1
          • J jsulm
            14 Dec 2022, 12:17

            @Qt-embedded-developer said in why QProcess not show output of ls /dev/sd* command ?:

            as per my case what i need to write in above ?

            What exactly is not clear?

            Q Offline
            Q Offline
            Qt embedded developer
            wrote on 14 Dec 2022, 12:19 last edited by Qt embedded developer
            #12

            @jsulm sorry its clear. i have to try. but if possible can you give example so it can help better.

            C 1 Reply Last reply 14 Dec 2022, 12:36
            0
            • Q Qt embedded developer
              14 Dec 2022, 12:19

              @jsulm sorry its clear. i have to try. but if possible can you give example so it can help better.

              C Offline
              C Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on 14 Dec 2022, 12:36 last edited by
              #13

              @Qt-embedded-developer said in why QProcess not show output of ls /dev/sd* command ?:

              but if possible can you give example so it can help better.

              Maybe reading the answers would help - it was already given...

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              Q 1 Reply Last reply 14 Dec 2022, 12:39
              0
              • C Christian Ehrlicher
                14 Dec 2022, 12:36

                @Qt-embedded-developer said in why QProcess not show output of ls /dev/sd* command ?:

                but if possible can you give example so it can help better.

                Maybe reading the answers would help - it was already given...

                Q Offline
                Q Offline
                Qt embedded developer
                wrote on 14 Dec 2022, 12:39 last edited by Qt embedded developer
                #14

                @Christian-Ehrlicher i have tried like below but i am getting empty list from fileinfolist

                QString myPath="/dev";
                        QDir dir;
                        dir.setPath(myPath);
                        QStringList filters;
                        filters<<"sd";
                        dir.setFilter( QDir::AllEntries | QDir::System);
                        dir.setNameFilters(filters);
                        dir.setSorting(QDir::Name );
                        QFileInfoList list = dir.entryInfoList();
                
                

                why my list is not giving file name what is expected ?

                J 1 Reply Last reply 14 Dec 2022, 13:02
                0
                • C Offline
                  C Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on 14 Dec 2022, 12:43 last edited by
                  #15

                  Because there is no /dev/sd in your directory. Please read the documentation...

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  Q 1 Reply Last reply 14 Dec 2022, 12:45
                  0
                  • C Christian Ehrlicher
                    14 Dec 2022, 12:43

                    Because there is no /dev/sd in your directory. Please read the documentation...

                    Q Offline
                    Q Offline
                    Qt embedded developer
                    wrote on 14 Dec 2022, 12:45 last edited by
                    #16

                    @Christian-Ehrlicher actually above code i written to find name that start with sd .

                    C 1 Reply Last reply 14 Dec 2022, 12:50
                    0
                    • Q Qt embedded developer
                      14 Dec 2022, 12:45

                      @Christian-Ehrlicher actually above code i written to find name that start with sd .

                      C Offline
                      C Offline
                      Christian Ehrlicher
                      Lifetime Qt Champion
                      wrote on 14 Dec 2022, 12:50 last edited by Christian Ehrlicher
                      #17

                      @Qt-embedded-developer said in why QProcess not show output of ls /dev/sd* command ?:

                      actually above code i written to find name that start with sd .

                      No, RTFM!

                      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                      Visit the Qt Academy at https://academy.qt.io/catalog

                      1 Reply Last reply
                      0
                      • Q Qt embedded developer
                        14 Dec 2022, 12:39

                        @Christian-Ehrlicher i have tried like below but i am getting empty list from fileinfolist

                        QString myPath="/dev";
                                QDir dir;
                                dir.setPath(myPath);
                                QStringList filters;
                                filters<<"sd";
                                dir.setFilter( QDir::AllEntries | QDir::System);
                                dir.setNameFilters(filters);
                                dir.setSorting(QDir::Name );
                                QFileInfoList list = dir.entryInfoList();
                        
                        

                        why my list is not giving file name what is expected ?

                        J Offline
                        J Offline
                        JonB
                        wrote on 14 Dec 2022, 13:02 last edited by
                        #18

                        @Qt-embedded-developer said in why QProcess not show output of ls /dev/sd* command ?:

                        filters<<"sd";

                        void QDir::setNameFilters(const QStringList &nameFilters)

                        Each name filter is a wildcard (globbing) filter that understands * and ? wildcards. See QRegularExpression::fromWildcard().

                        1 Reply Last reply
                        0

                        17/18

                        14 Dec 2022, 12:50

                        • Login

                        • Login or register to search.
                        17 out of 18
                        • First post
                          17/18
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved