Menu

Practice questions: Batch file control

Pick an answer and press "Check answer" to see right away whether you got it. If you are unsure, open "Read the article" to review the command and then try again. Questions you answer correctly are remembered in this browser.

23 questions Solved 0 / 23

call - Execute Other Batch Files

Read the article →

call - Execute Other Batch Files — Question 1

There are two batch files, caller.cmd and callee.cmd. If you execute caller.cmd in this state, which one will be the third to be displayed by the echo command?

caller.cmd
@echo off

echo Started caller.cmd.

call callee.cmd

echo Finished caller.cmd.
callee.cmd
@echo off

echo Started callee.cmd.

echo Finished callee.cmd.

Choose one answer.

  1. Started callee.cmd.
  2. Finished callee.cmd.
  3. Finished caller.cmd.

choice - Prompt the user for input

Read the article →

choice - Prompt the user for input — Question 1

What is the choice command in Command Prompt used for?

Choose one answer.

  1. Rename a file or directory
  2. Receive keyboard input from the user
  3. Copy a file or directory

choice - Prompt the user for input — Question 2

How do you get the result after receiving input from the user with the choice command?

Choose one answer.

  1. The pressed key is stored in the variable %choice%
  2. A number indicating the position of the choice is stored in the variable %errorlevel%
  3. The pressed key is stored in the variable %input%

choice - Prompt the user for input — Question 3

What is the default prompt message for the choice command?

Choose one answer.

  1. [Y,N]?
  2. [A,B,C]?
  3. [1,2,3]?

cmd - Start the command processor

Read the article →

cmd - Start the command processor — Question 1

Which option runs one command and then leaves the Command Prompt open and waiting for input?

Choose one answer.

  1. /c
  2. /k
  3. /q

cmd - Start the command processor — Question 2

How can you run an internal cmd.exe command such as mklink from PowerShell?

Choose one answer.

  1. Type mklink as is
  2. Run it like cmd /c mklink …
  3. Run it like cmd /q mklink …

cmd - Start the command processor — Question 3

What happens to an environment variable you set in a child Command Prompt started with cmd after you return to the parent with exit?

Choose one answer.

  1. It is also reflected in the parent
  2. It is not reflected in the parent
  3. It is saved to the registry

exit - Terminate a program

Read the article →

exit - Terminate a program — Question 1

What is the purpose of the “exit” command in Command Prompt?

Choose one answer.

  1. Delete files or directories.
  2. End the current Command Prompt session.
  3. Minimize the Command Prompt temporarily.

exit - Terminate a program — Question 2

Which of the following options correctly sets the specified exit code?

Choose one answer.

  1. exit
  2. exit /b code
  3. exit /b 100

exit - Terminate a program — Question 3

Two batch files, caller.cmd and callee.cmd, are prepared, and callee.cmd is called from caller.cmd. If exit without options is executed in callee.cmd, what will be the behavior of caller.cmd?

Choose one answer.

  1. The processing of callee.cmd ends and the processing of caller.cmd continues.
  2. The processing of callee.cmd ends and the processing of caller.cmd also ends.
  3. The processing of callee.cmd continues and the processing of caller.cmd also continues.

for - Loop Command

Read the article →

for - Loop Command — Question 1

Which is the correct FOR statement to display 1, 2, 3 in sequence inside a batch file?

Choose one answer.

  1. FOR %%i IN (1 2 3) DO echo %%i
  2. FOR %%i (1 2 3) DO echo %%i
  3. FOR %%i IN 1 2 3 DO echo %%i

for - Loop Command — Question 2

Which option is used to loop over a numeric range?

Choose one answer.

  1. /L
  2. /D
  3. /R
  4. /F

for - Loop Command — Question 3

Which is the correct syntax to count from 1 to 10 with the /L option?

Choose one answer.

  1. FOR /L %%n IN (1, 1, 10)
  2. FOR /L %%n IN (1-10)
  3. FOR /L %%n IN (1 TO 10)

goto - Jump to a Label

Read the article →

goto - Jump to a Label — Question 1

Select the incorrect statement about the GOTO command.

Choose one answer.

  1. GOTO :EOF ends the execution of the batch file
  2. After jumping with the GOTO command, execution can return to the original position
  3. Label names are not case-sensitive

if - Conditional Branching

Read the article →

if - Conditional Branching — Question 1

Choose the incorrect description about the IF command.

Choose one answer.

  1. IF /I performs a case-insensitive comparison
  2. IF ERRORLEVEL 1 is true only when ERRORLEVEL equals exactly 1
  3. IF DEFINED checks whether a variable is defined

PAUSE - Pause — Question 1

How do you hide the default PAUSE message (“Press any key to continue …”)?

Choose one answer.

  1. Write pause >nul
  2. Write pause /q
  3. Write pause /silent

rem - Comment — Question 1

Which of the following is treated as an official comment in a batch file?

Choose one answer.

  1. rem This line is a comment
  2. echo This line is a comment
  3. pause This line is a comment

rem - Comment — Question 2

What do you often write first to suppress command line display for the entire batch file?

Choose one answer.

  1. @echo off
  2. @rem
  3. setlocal

setlocal, endlocal

Read the article →

setlocal, endlocal — Question 1

What value is displayed last when the following code is run?

@echo off
set VAR=FirstValue
setlocal
set VAR=SecondValue
endlocal
echo %VAR%

Choose one answer.

  1. FirstValue
  2. SecondValue
  3. Empty string
  4. An error occurs

setlocal, endlocal — Question 2

In a block that uses setlocal enabledelayedexpansion, which notation references the updated value?

Choose one answer.

  1. %COUNT%
  2. !COUNT!
  3. $COUNT$

start - Run Other Batch Files

Read the article →

start - Run Other Batch Files — Question 1

Which command launches another batch file asynchronously and moves on to the next step without waiting for it to finish?

Choose one answer.

  1. start "" sub.cmd
  2. start "" /wait sub.cmd
  3. call sub.cmd

start - Run Other Batch Files — Question 2

Which is the correct way to run a batch file whose path contains spaces with start?

Choose one answer.

  1. start "C:\My Scripts\job.cmd"
  2. start "" "C:\My Scripts\job.cmd"
  3. start /d "C:\My Scripts\job.cmd"

timeout - Wait

Read the article →

timeout - Wait — Question 1

Which command waits indefinitely until the user takes some action?

Choose one answer.

  1. timeout
  2. timeout /t -1
  3. timeout /t 9999 /nobreak

Other topics

← Back to all practice questions