Re: [問題] Redirect stderr

看板Linux作者 (BIT一生)時間12年前 (2012/07/22 06:47), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串3/6 (看更多)
※ 引述《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: 60.245.65.148
文章代碼(AID): #1G2p5jNy (Linux)
討論串 (同標題文章)
文章代碼(AID): #1G2p5jNy (Linux)