0

I'm trying to copy a file I have attached to my program like resource in a /usr/share/postgresql/10/extension/ (needs sudo rights)

If the destination path was in /home I could do something like that:

QFile file(QStringLiteral(":/resourcefile"));
if(file.open(QIODevice::ReadOnly))
{
    file.copy("/home/user/......./resourcefile");
}

But it's not my case. Therefore I must to use QProcess (I think) in this way:

QProcess process1, process2;

process1.setStandardOutputProcess(&process2);
process1.start("echo mypass");
process2.start("sudo -S cp <resourcefile> /usr/share/postgresql/10/extension/file.sql");
process2.setProcessChannelMode(QProcess::ForwardedChannels);
bool retval = false;
QByteArray buffer;
while ((retval = process2.waitForFinished()));
    buffer.append(process2.readAll());
.....

And the question is....how could I pass the <resourcefile> to process2?

user3733164
  • 531
  • 4
  • 17

1 Answers1

0

Use this methods:

QProcess::setArguments(const QStringList &arguments)
QProcess::setNativeArguments(const QString &arguments)
QProcess::setStandardInputFile(const QString &fileName)
QProcess::setStandardOutputFile(const QString &fileName, QIODevice::OpenMode mode = Truncate)

look at this: https://doc.qt.io/qt-5/qprocess.html

bogdyname
  • 358
  • 2
  • 10
  • Thank you, but I can't help me. My real problem is that "resourcefile" is not a phisical file that bash can use. I go to edit the question for clarify – user3733164 Jun 06 '20 at 18:12