-1

According to this I can get it using this command:

dscl . -read ~/ UserShell

So, I wrote this code using Qt:

QProcess p;
p.setProcessChannelMode(QProcess::MergedChannels);
p.start("dscl", QStringList() << "." << "-read" << "~/" << "UserShell");
p.waitForFinished();
auto result = QString::fromUtf8(p.readAll());

But, the result is empty. What am I doing wrong? This command works fine in the Terminal app.

Addition #1. This works, but it looks stupid :)

p.start("bash", QStringList() << "-c" << "dscl . -read ~/ UserShell")
Alexander Dyagilev
  • 1,139
  • 1
  • 15
  • 43
  • Using that overload of `QProcess::start` will bypass the shell meaning the `~/` token is not expanded. You need to perform that expansion yourself. – G.M. Nov 02 '21 at 11:39

1 Answers1

1

I think the only alternative is to expand the ~ yourself. So something like...

p.start("dscl", QStringList() << "." << "-read" << QDir::homePath() << "UserShell");
Nimantha
  • 6,405
  • 6
  • 28
  • 69
G.M.
  • 12,232
  • 2
  • 15
  • 18