220-1102 Question 781
Single answer4.8 Explain the basics of scripting.A technician needs to collect troubleshooting data from several Windows 10 PCs before escalating an issue. The technician wants to create a script that displays each computer's hostname and IP configuration, then saves the results to a text file for review. Which command line in a Windows batch file will correctly append both command outputs to the same file?
- A
hostname > report.txt && ipconfig >> report.txt
- B
hostname >> report.txt && ipconfig > report.txt
- C
hostname | report.txt && ipconfig | report.txt
- D
hostname < report.txt && ipconfig < report.txt
Show answer and explanation
Correct answer: A
Explanation
This question tests practical understanding of basic scripting and command-line redirection in Windows batch files, which is part of A+ Core 2 scripting fundamentals. For simple automation tasks, technicians often use batch files to run commands and capture output for troubleshooting. In Command Prompt syntax, > redirects standard output to a file and overwrites the file if it already exists, while >> appends output to the end of the file. The pipe operator | is used to pass one command's output as another command's input, not to write directly to a file. Input redirection with < is used to feed file contents into a command. Microsoft Command-Line documentation and common Windows batch scripting practices support these behaviors. In a real support environment, choosing the correct redirection operators prevents accidental loss of collected diagnostic data.
- A. Correct.
Correct. In a Windows batch file, the > operator creates or overwrites a file, so using it with the first command starts the report file with the hostname output. The >> operator appends output to the existing file, so ipconfig is added to the same report instead of replacing it. The && operator runs the second command only if the first command succeeds, which is appropriate in a simple data-collection script.
- B. Incorrect.
Incorrect. This reverses the redirection behavior in a way that can overwrite the file after the first command runs. hostname >> report.txt appends, but then ipconfig > report.txt overwrites the file with only the IP configuration output. A technician might choose this if they remember that >> appends but forget that > replaces existing file contents.
- C. Incorrect.
Incorrect. The pipe operator | sends the output of one command to another command's input; it does not send output directly to a file name. report.txt is not a command that can receive piped input in this context. This distractor reflects a common confusion between piping and output redirection.
- D. Incorrect.
Incorrect. The < operator is for input redirection, meaning a command reads from a file rather than writes to one. Using < report.txt would attempt to feed the contents of report.txt into hostname or ipconfig, which is not the goal here and would not create the desired output file.