I’m using Ubuntu 11.10.
If I open a terminal and call: ps all I get the results truncated (i.e. 100 characters at most for each line) to the size of the terminal window.
If I call ps all > file The lines don’t get truncated and all the information is in the file (There is a line that has ~200 characters)
In C, I am trying to achieve the same but the lines get truncated.
I’ve tried
int rc = system("ps all > file");
as well as variants of popen.
I assume the shell being used by system (and popen) defaults the output of each line to 80, which make sense if I were to parse it using popen, but since I am piping it to a file I expect it to disregard the size of the shell like I experienced when doing it in my shell.
TL;DR
How can I make sure ps all > file doesn’t truncate lines when called from C application?
As a workaround, try passing
-wor possibly-wwtopswhen you invoke it.From the man page (BSD):
Linux:
Alternatively,
You might have some success doing a
fork/exec/waityourself instead of usingsystem; omitting error handling for brevity: