View Full Version : Try to use QProcess

2nd August 2010, 20:03
Hi, I'm try to do a simple tool in QT; this tool convert files from dos format to unix format, using tr program

The I use a QProcess to comunicate tr with my program, but I failed to make it work, because in the error output ( readAllStandardError() ) say:
"usage: tr [-Ccsu] string1 string2
tr [-Ccu] -d string1
tr [-Ccu] -s string1
tr [-Ccu] -ds string1 string2"

and the files are not modified...

What is my mistake??

The statement I am trying to use is:

tr -d "\015" < DOS_File

The code is this:

QProcess *td;
QString prg,file;

td = new QProcess(this);

prg = "tr -d \"\\015\" < " + file;

I have also tried to use this:

QProcess *td;
QStringList inst;
QString file;

td = new QProcess(this);

inst<< "-d"<<"\"\\015\""<<"<"<<file;

I'm use QT 4.6 in mac


2nd August 2010, 20:12
Arguments are given separately

Edit: hmm, ignore this reply of me, it's not correct.

2nd August 2010, 21:29
Note that "<" is not actually an argument to "tr", but a shell command that redirects the contents of a file to the application.

You probably need two QProcesses - one for "cat file" (or something similar) and another for "tr options". Then redirect the output from "cat" to the input of "tr".

Or make your application write a small script file for the given arguments, and execute the script with one single QProcess.

Maybe there are other more elegant solutions.

[edit] One more possibility: let the shell parse and execute your complete statement, e.g.

td->start("sh -c \"tr -d \"\\015\" < " + file + "\"");