作为一种解决方法,请尝试在调用它时传递-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 <unistd.h>
#include <stdio.h>
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);
}