Difficulty: Medium
Correct Answer: SORT < filename
Explanation:
Introduction / Context:
DOS commands often use redirection to supply input or capture output. The SORT utility reads lines from standard input and writes sorted lines to standard output by default (ascending order). Choosing the correct redirection operator is essential for the desired behavior.
Given Data / Assumptions:
Concept / Approach:
Input redirection in DOS uses the less-than symbol. “SORT < filename” sends the file's content to SORT via standard input. “SORT filename” treats “filename” as a literal string input on some DOS variants or may be rejected; the canonical method is input redirection. “SORT > filename” writes output to a file but does not feed input. Pipes “|” connect outputs to inputs of programs, not files directly.
Step-by-Step Solution:
Verification / Alternative check:
Run “TYPE filename | SORT” to confirm equivalent behavior. Compare with “SORT > out.txt” which captures output but still requires input via stdin.
Why Other Options Are Wrong:
SORT filename: not the canonical usage for DOS SORT input. SORT > filename: redirects output only. SORT | filename: invalid piping to a file; pipes connect program to program.
Common Pitfalls:
Confusing input and output redirection; forgetting that SORT consumes stdin by default; overwriting files unintentionally with output redirection.
Final Answer:
SORT < filename
Discussion & Comments