看板 Linux 關於我們 聯絡資訊
你是想stdout&stderr -> screen 且 stderr -> file 嗎? 如果我沒搞錯的話應該可以用下面的script完成 str="$@"; ${str#$1} 3>&1 1>&2 2>&3 | tee $1 ; 然後把上面那一行存成xxx.sh 或 xxx 之後你只要呼叫 sh xxx.sh [你要輸出stderr的filename] [你的command] 就可以了 基本上就是swap stdout & stderr 然後用tee去存 嫌打sh太麻煩你就chmod一下即可 ※ 引述《bitlife (BIT一生)》之銘言: : ※ 引述《kdjf (我抓得到什麼呢?)》之銘言: : : 可是我現在寫的會多一份PS1,還不知到為什麼 : : 有誰可以幫我補上XD? : 我提供另一個作法,但缺點是會沒有 prompt,我還沒找到如何解決 XD : 將下列程式存成 err2log.c 然後用 cc -o err2log err2log.c 編譯 : 以如下命令執行 : $ ./err2log 輸出檔案的路徑 : 程式開始: : #include <stdio.h> : #include <stdlib.h> : #include <errno.h> : #include <fcntl.h> : #include <unistd.h> : main(int argc, char *argv[]) { : if (argc<2) { : printf("Usage: err2log output-file\n"); : exit(0); : } : close(2); : int fd = open(argv[1], O_CREAT|O_TRUNC|O_RDWR, 0644); : if (fd<0) { : printf("errno=%d\n", errno); : perror(""); : exit(errno); : } : if (fd!=2) { : printf("Error!\n"); : exit(0); : } : execl("/bin/bash", "/bin/bash", NULL); : } : 程式結束 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.33.239.83
ALTandTAB:發現順序好像會怪怪的... 07/22 13:36