[英]The text to be printed is being printed on the command line rather than print space while using fork on terminal
[英]Prevent line being printed to command line pipe to file
標題可能有點令人困惑..所以這是我對它的解釋:
我的程序有一個命令:
c file1.txt > file2.txt
命令行中的此命令獲取第一個文件,並將程序的輸出(已打印)通過管道傳輸到第二個文件。
因此,即時通訊會在以下位置掃描用戶消息:
printf("Enter a message:");
char *message = malloc(sizeof(char) * 256);
scanf("%s", message);
printf("Your message is: %s", message);
但這會將兩個printf(...)
語句都打印到我的管道文件中,而我只想要第二個。 我該如何預防呢?
謝謝!
一種方法是將stderr
用於您不想復制到輸出文件的信息:
fprintf(stderr, "Enter a message:");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.