PDA

View Full Version : List the output of ls /dev/tty* using QProcess



arunkumaraymuo1
3rd September 2013, 06:29
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




QProcess* process = new QProcess(this);
QStringList sArgs;
sArgs << "/dev/tty*";
process->start("ls", sArgs);
process->waitForFinished(-1);
qDebug() << process->readAllStandardOutput();
qDebug() << process->readAllStandardError();

ChrisW67
3rd September 2013, 07:26
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)

nix
3rd September 2013, 07:35
QProcess run a process and not a shell so the * wilcard does not work.
This will work, but it's ugly

QProcess* process = new QProcess();
QStringList sArgs;
process->start("sh -c \"ls /dev/tty*\"");
process->waitForFinished(-1);
qDebug() << process->readAllStandardOutput();
qDebug() << process->readAllStandardError();
This is better :

QDir lsDev("/dev/");
lsDev.setNameFilters(QStringList() << "tty*");
qDebug() << lsDev.entryList(QDir::System);