0

I am trying to call tar from a Qt project:

QProcess::execute("/bin/su", {"-", "user", "-c", "\'/bin/tar xpf /tmp/smt.tbz2 -C /tmp\'"})

Bit I am getting:

-su: /bin/tar xpf /tmp/smt.tbz2 -C /tmp: No such file or directory

It looks like the su command does not interpret correctly the command after -c.

robert
  • 3,539
  • 3
  • 35
  • 56
  • Also see [Run sudo command in Qt QProcess](https://stackoverflow.com/q/32063190/608639), [Executing Linux command as root in Qt](https://stackoverflow.com/q/7036588/608639), [How to get root permission inside Qt program?](https://stackoverflow.com/q/19840163/608639), [QProcess, communicate with 'su' command](https://www.qtcentre.org/threads/24898-QProcess-communicate-with-su-command), etc. – jww Apr 26 '19 at 13:13

1 Answers1

2

I think the problem is that you are quoting the command to run explicitly: QProcess goes to some lengths to ensure parameters are passed as-is rather than being split any further.

Instead try...

QProcess::execute("/bin/su", {"-", "user", "-c", "/bin/tar xpf /tmp/smt.tbz2 -C /tmp"});
G.M.
  • 12,232
  • 2
  • 15
  • 18