dotjan
16th March 2012, 16:45
Hi, in my app it seems I cannot properly pass special characters as argument to the external program started with a QProcess instance.
The final command I have to execute is something like:
/usr/bin/rsync -n -v -a --exclude "/*/*/" --include "*/" --include "*.txt" --exclude "*" /dir1/ /dir2
--exclude and --include are rsync's filter rules which must be written using special characters as you can see.
A snip of the code to generate them:
args << "--exclude";
args << "\"/\*/\*/\"";
args << "--include";
args << "\"\*/\"";
args << "--include";
args << "\"\*.txt\"";
args << "--exclude";
args << "\"\*\"";
You see I use \ as escape character for "" and *. However it seems it is not enough... when I then run the application, I can intercept the rsync command on the system (ps aux | grep rsync) and I can see it running exactly as expected:
/usr/bin/rsync -n -v -a --exclude "/*/*/" --include "*/" --include "*.txt" --exclude "*" /dir1/ /dir2
Also, if I debug with qdebug the command executed I see:
"/usr/bin/rsync" ("-n", "-v", "-a", "--exclude", ""/*/*/"", "--include", ""*/"", "--include", ""*.txt"", "--exclude", ""*"", "/dir1/", "/dir2")
everything seems to be ok.However, the output generated in my app does not reflect it, just like the filter rules are not applied. I suspect there is something with special characters and escaping... but really do not know how to go ahead.. I am struggling...
Thanks,
Jan
The final command I have to execute is something like:
/usr/bin/rsync -n -v -a --exclude "/*/*/" --include "*/" --include "*.txt" --exclude "*" /dir1/ /dir2
--exclude and --include are rsync's filter rules which must be written using special characters as you can see.
A snip of the code to generate them:
args << "--exclude";
args << "\"/\*/\*/\"";
args << "--include";
args << "\"\*/\"";
args << "--include";
args << "\"\*.txt\"";
args << "--exclude";
args << "\"\*\"";
You see I use \ as escape character for "" and *. However it seems it is not enough... when I then run the application, I can intercept the rsync command on the system (ps aux | grep rsync) and I can see it running exactly as expected:
/usr/bin/rsync -n -v -a --exclude "/*/*/" --include "*/" --include "*.txt" --exclude "*" /dir1/ /dir2
Also, if I debug with qdebug the command executed I see:
"/usr/bin/rsync" ("-n", "-v", "-a", "--exclude", ""/*/*/"", "--include", ""*/"", "--include", ""*.txt"", "--exclude", ""*"", "/dir1/", "/dir2")
everything seems to be ok.However, the output generated in my app does not reflect it, just like the filter rules are not applied. I suspect there is something with special characters and escaping... but really do not know how to go ahead.. I am struggling...
Thanks,
Jan