PtyProcess superflous linebreaks

Thomas Friedrichsmeier thomas.friedrichsmeier at
Tue Nov 20 16:48:28 GMT 2007


this is a minor issue, but still a bit annoying. Consider the following 
command line:

kdesu -t -c 'while (true); do echo -n "X"; sleep 1; done;'

Unless you click "Ignore", this will output each "X" on a separate line, 
instead of all on one line, as would be expected.

The problem seems to be in KDESU::PtyProcess. Here we have:

int PtyProcess::waitForChild()
            QByteArray line = readLine(false);
            while (!line.isNull())
                    fputs(line, stdout);
                    fputc('\n', stdout);
                line = readLine(false);

which actually produces the above output. As you can see it manually adds a 
newline after each bit of output. This is needed, as readLine() always strips 
the newline characters. However, in some cases (like the above), readLine() 
may return less than a full line of output, and there is no way for the 
calling code to differentiate this.

The most obvious solution would be to make the readLine() return value include 
the newline character if there is one, instead of stripping it, as it does 
currently. The return value would then include information on whether a full 
line was read, or maybe only a few characters.

Obviously, however, this would break code that expects newlines to be 
stripped, and probably it's too late for this kind of disruptive fix.

Another option would be to add a parameter "bool strip_linebreaks=true" to 
readLines(), but I'm not clear on whether this sort of API change is still 
acceptable. Ideas?

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
URL: <>

More information about the kde-core-devel mailing list