- 1 year ago
Spawing a fully interactive Windows cmd.exe shell
To spawn a fully interactive Windows Command Prompt (cmd.exe) shell from another Command Prompt or batch file, you can use the start
command with the /wait
and /i
options. The /wait
option ensures that the original command prompt waits for the new shell to close before continuing, and the /i
option starts an interactive session. Here's the command:
batchstart /wait /i cmd.exe
Save the above command in a batch file (e.g., spawn_shell.bat
) and execute it from a Command Prompt. This will open a new interactive Command Prompt window. You can type commands in the new shell, and it will behave as a fully interactive session.
Keep in mind that when you execute this batch file or command, the current Command Prompt will wait for the spawned shell to be closed before you can continue using it. If you close the new shell, the original Command Prompt will resume execution.
If you need more control over the spawned shell, such as interacting with its input and output programmatically, you may need to use a more advanced scripting language like Python or PowerShell. These languages offer more flexibility in handling interactive sessions programmatically.