简体   繁体   中英

How to run command line with QProcess?

i have a application (X)Medcon, i want to run command line (convert file) with QProcess . I tried but it is not success. This is my code

   convertDicomProcess = new QProcess(this);
   QString program = "C:\\Program Files\\XMedCon\\bin\\xmedcon.exe";
   QStringList arguments;
   arguments << "medcon"<< "-f" << "F:/33.nii" << "-c" << "dicom" << "-o" << "F:/33.dcm";

   convertDicomProcess->start(program, arguments);
   convertDicomProcess->waitForFinished();
   QByteArray output = convertDicomProcess->readAll();
   convertDicomProcess->close();

When i run command line with

medcon -f E:\\55.nii -c dicom -o E:\\55.dcm

it is convert success

If you path exists, I think you need to use quotes (\\") in the string for the one:

QString program = "\"C:\\Program Files\\XMedCon\\bin\\xmedcon.exe\"";
...

Try:

QStringList arguments;
arguments << "/c" << program << "-f" << "F:/33.nii" << "-c" << "dicom" << "-o" << "F:/33.dcm";

convertDicomProcess->start("cmd.exe", arguments);

Test if you really need "medcon" as an argument again, I do not know since I do not know the "medcon" program. If yes change it to:

arguments << "/c" << program << "medcon" << "-f" << "F:/33.nii" << "-c" << "dicom" << "-o" << "F:/33.dcm";

This code tries to run the medcon program in a shell.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM