ฉันรู้วิธีเปลี่ยนเส้นทางไปยังไฟล์และใช้ที ในระดับพื้นฐาน ดังนั้น
$ alias outanderr='bash -c "echo stdout >&1; echo stderr >&2"'
# A fake "application" displaying both output and error messages.
$ outanderr 1>file # redirect stdout to a file, display stderr
stderr
$ outanderr 2>file # redirect stderr to a file, display stdout
stdout
$ outanderr 1>file 2>&1 # redirect both to a file, display nothing
$ outanderr | tee file; echo "-- file contents --" && cat file
# redirect stdout to a file, display both (note: order is messed up)
stderr
stdout
-- file contents --
stdout
$ outanderr 2>&1 | tee file; echo "-- file contents --" && cat file
# redirect both to a file, display both
stdout
stderr
-- file contents --
stdout
stderr
คำถามคือสิ่งที่จะเขียนแทนเครื่องหมายคำถามเพื่อรับผลลัพธ์ด้านล่าง:
$ outanderr ???; echo "-- file contents --" && cat file
# redirect both to a file, display stderr
stderr
-- file contents --
stdout
stderr
Constaints:
- สมมติว่าทุบตี
- คำสั่งซื้อควรถูกเก็บไว้ในไฟล์
- เนื้อหา stderr จะแสดงในแบบเรียลไทม์โดยบรรทัดคือไม่มีการบัฟเฟอร์
- สามารถใช้ไฟล์สคริปต์แยกกันได้
- อาจจำเป็นต้องใช้เวทย์มนตร์
@ เควินฉันคิดว่าคำถามทั่วไปมากกว่านั้น ที่นี่
—
lgeorget
outanderr
เป็นเพียงนามแฝงที่พิมพ์บรรทัดไปยัง stdout และอีกชื่อเป็น stderr แนวคิด (ถ้าเป็นไปได้) คือการสร้างโซลูชันทั่วไปที่สามารถทำงานกับโปรแกรมใด ๆ โดยไม่ต้องแก้ไข
@georget ฉันเข้าใจว่า แต่ฉันไม่เชื่อว่าเป็นไปได้ที่จะปฏิบัติตามข้อ จำกัด ทั้งหมดในการแก้ปัญหาทั่วไปอย่างเคร่งครัดดังนั้นฉันจึงเห็นว่าเราจะได้รับเฉพาะเจาะจงหรือไม่
—
Kevin
@Igeorget ถูกต้อง
—
TWiStErRob
outanderr
คุณมีโปรแกรมที่ควบคุมได้มากแค่ไหน?