I am trying to use a special program called RNAPlot in a QProcess. This program takes an RNA structure file and generates a picture of the structure. The details of this process aren't very pertinent to this problem, it seems to me, but the important part is that it takes an input file and generates an output file (in my case I am trying to have it generate an SVG file).

The place where this QProcess is called is part of a larger project (a QMainWindow calls the class which tries to instantiate the particular QProcess). I can get the QProcess to accept an input file, and it will generate an output file, but it will only write that file to the current working directory. I have tried redirecting its standard output to a new file, but it seems the program (RNAPlot) doesn't use stdout, but opens a new file in the cwd and writes to that. Is there a way to redirect that into a file I specify? Or to have it not write that file but return it to the program so I can write it to a byte array? Or is the fact that the program, RNAPlot, opens its own file and writes to it mean that I can't redirect that like I would if it just wrote to stdout?

This code is for a function in a class that the QMainWindow calls, but I suspect that this is enough context to help with the specific action I would like to happen.
Qt Code:
  1. void RNAModelGen::generate2DModel(QString filepath){
  2.  
  3. //create unique file to write structure (picture) to
  4. QTemporaryFile* rnaPict = new QTemporaryFile("rnaPictXXXXXX.svg");
  5. rnaPict->setAutoRemove(false);
  6. if(!rnaPict->open()){
  7. qCritical() << "Did not open temp file!";
  8. }else{
  9. qDebug() << "Temp File name: " << rnaPict->fileName();
  10. }
  11. QString pictFile = rnaPict->fileName();
  12. rnaPict->close();
  13.  
  14. rnaPlotCmd = "C:\\Program Files (x86)\\ViennaRNA Package\\RNAplot.exe";
  15. rnaPlotArgs << "-o" << "svg" << filepath;
  16.  
  17. // start RNAplot
  18. rnaPlot = new QProcess(this);
  19. rnaPlot->setProgram(rnaPlotCmd);
  20. rnaPlot->setArguments(rnaPlotArgs);
  21. rnaPlot->start(QIODevice::ReadWrite);
  22.  
  23. if(!rnaPlot->waitForFinished()){
  24. qCritical() << "RNAPlot failed to finish";
  25. qCritical() << rnaPlot->errorString();
  26. }
  27.  
  28. QByteArray svg_pict = rnaPlot->readAll(); // This is where the problem is!
  29. // nothing is returned and svg_pict ends up empty
  30. // (I know because I used debugger to check)
  31.  
  32. // write svg_pict to rnaPictXXXXXX.svg
  33. // NOT implemented yet (doesn't matter at this point since svg_pict is empty)
  34.  
  35. }
To copy to clipboard, switch view to plain text mode 

In short the program I am wanting to use in a QProcess, RNAPlot, always writes its output to the cwd, and I would rather it send its output to a file I specify, or return it so I can put it into a byte array and write it to a file.

Thank you in advance for anyone who is able to help me!

If it's helpful or you're curious about the RNA software I'm using, it's part of ViennaRNA: https://www.tbi.univie.ac.at/RNA/
Also there's a man page for RNAPlot: https://www.tbi.univie.ac.at/RNA/RNAplot.1.html