why QProcess not show output of ls /dev/sd* command ?
-
@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/lsI'm wondering why you need QProcess for such a task at all? You can simply use https://doc.qt.io/qt-6/qdir.html
wrote on 14 Dec 2022, 12:14 last edited by@jsulm means i just need to check there is file name start with sd is there on not int /dev directory
-
@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 withsd
. OrQFileInfoList 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 parsels
's output.wrote on 14 Dec 2022, 12:16 last edited by@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 ?
-
@jsulm means i just need to check there is file name start with sd is there on not int /dev directory
@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).
-
@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 ?
@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?
-
@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?
wrote on 14 Dec 2022, 12:19 last edited by Qt embedded developer@jsulm sorry its clear. i have to try. but if possible can you give example so it can help better.
-
@jsulm sorry its clear. i have to try. but if possible can you give example so it can help better.
@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-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...
wrote on 14 Dec 2022, 12:39 last edited by Qt embedded developer@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 ?
-
Because there is no
/dev/sd
in your directory. Please read the documentation... -
Because there is no
/dev/sd
in your directory. Please read the documentation...wrote on 14 Dec 2022, 12:45 last edited by@Christian-Ehrlicher actually above code i written to find name that start with sd .
-
@Christian-Ehrlicher actually above code i written to find name that start with sd .
Lifetime Qt Championwrote on 14 Dec 2022, 12:50 last edited by Christian Ehrlicher@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!
-
@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 ?
wrote on 14 Dec 2022, 13:02 last edited by@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().
17/18