I have a exe folder located in one folder, and then all of my config files in another. In order to run the program:
Shown below, I have this working correctly using system calls, but I need a system agnostic way of doing this.
void MainWindow::on_pushButton_clicked()
{
std::system("cd Path_To_ConfigFolder & Absolute_Path_To_Exe RunFile.txt > logfile.txt");
}
The above works great. Although it only works on Windows.. so I did some research on using QProcess to create a more system agnostic way.. and no matter what I try I can't seem to get this to work. See below:
void MainWindow::on_pushButton_clicked()
{
QProcess p;
QStringList params;
p.setWorkingDirectory("Path_To_ConfigFolder");
params << " RunFile.txt > logfile.txt";
p.start("Absolute_Path_To_Exe", params);
p.waitForFinished(-1);
}
Note: For the above example (using QProcess), I am \\\\
for all my paths, and all my paths are correct.
What am I doing wrong here?
Name of executable would be starting with ".\\"
if it is in local folder to be system-agnostic. Linux shell and PowerShell require that.
">" - output redirection isn't an argument of process, that won't work. You have to redirect output channel to your or a secondary process.
p.setStandardOutputFile("log_file.txt")
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.