Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Cmd: send a child's stdout or stderr to a file

Đã đóng
#532 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Một pull request liên quan đã được merge.

  • #534 của @lukewilliamboswell — đã merge

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
48/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
rust
Lĩnh vực
cli

Hướng nghiên cứu

Start by reading the existing Cmd stdout and stderr mode definitions and spawn implementation, then check their tests to see how child output is currently handled. The issue sketches file output modes with truncate or append behavior and merging stderr with stdout; compare those options with the existing API style. Done means a child can send stdout or stderr to a file as described, with tests covering the selected modes.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

A child's standard output can be inherited, discarded, captured, tee'd or piped, but not sent to a file. A long-running child whose output should end up on disk then needs a shell for the redirect:

child = Cmd.new("bash").args(["-c", "ssh … 'journalctl -k -f' > server.log 2>&1"]).spawn!()?

Our case: a race tool follows a remote server's kernel log and memory over one ssh session for hours, into a file (the "black box" read after a crash). The app is single-threaded and busy driving load the whole time, so it cannot read a Pipe and write the file itself. With Go we set cmd.Stdout to an *os.File.

A sketch, keeping Cmd's style:

StdoutMode : [Inherit, InheritStderr, Null, Capture, Tee, Pipe, File(Path, [Truncate, Append])]
StderrMode : [..., File(Path, [Truncate, Append]), MergeWithStdout]

child = Cmd.new("ssh").args(args).stdout(File("server.log", Truncate)).stderr(MergeWithStdout).spawn!()?

Opening the file in the host (with O_APPEND for Append) before the spawn would also make the redirect atomic in the way a shell's is. Could also take File.WriterOptions for its permissions.

Seen on 0.26.0-rc3.

Ngôn ngữ chính
Rust
Star
122
Fork
47
Merge trung bình
11 giờ 6 phút
Pull request đã merge (30 ngày)
21

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của roc-lang/basic-cli

Tất cả issue của roc-lang/basic-cli

Issue tương tự

Thêm issue về Rust

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.