John Ledbett..
6
作为一种变通方法,尝试通过-w或可能-ww以ps当你调用它.
从手册页(BSD):
-w Use 132 columns to display information, instead of the default which is your
window size. If the -w option is specified more than once, ps will use as many
columns as necessary without regard for your window size. When output is
not to a terminal, an unlimited number of columns are always used.
Linux的:
-w Wide output. Use this option twice for unlimited width.
或者,
你可能会取得一些成功fork/exec/wait而不是使用system; 省略错误处理以简化:
#include
#include
pid_t pid = fork();
if (!pid) {
/* child */
FILE* fp = fopen("./your-file", "w");
close(STDOUT_FILENO);
dup2(fileno(fp), STDOUT_FILENO);
execlp("ps", "ps", "all", (char*)NULL);
} else {
/* parent */
int status;
wait(&status);
printf("ps exited with status %d\n", status);
}