0

I want to open a cmd shell and set some command in the promt without executing them. The goal is: Shell opens with command (e.g. echo hello) and the user only need to press enter instead of typing it.

Is this possible? I found the /k switch like cmd /k echo hello but this executes the command immediately. The only workaround I see is something like cmd /k "pause && echo hello" but this is not very transparent as the user doesn't know what got executed.

Daniel
  • 968
  • 3
  • 13
  • 32

1 Answers1

0

So there are 2 ways of doing this:

Create a shortcut.

Right click in a folder where you want to store the shortcut

Select new Shortcut

In the command window, type the following:

cmd /k echo press Enter to continue ping localhost command && pause >nul && ping localhost

Click next and give it a name and save.

Now you can double click the file and it will print to screen:

press Enter to continue ping localhost command

when Enter is pressed, it will ping localhost

Batch File

Open notepad.exe

Type the following

@echo off
echo press Enter to continue ping localhost command
pause >nul
ping localhost
pause

Save the file to the desired location and give it a .cmd extension

Now you can double click the file and it will do the same as the previously created shortcut version.

As for transparency, if you want the use to see what will be running, you would need to show the user by echoing what will be done.. See the following example.

@echo off
echo echo hello
pause >nul
echo hello
echo ping localhost
pause >nul
ping localhost
pause..

this only duplicates the actual commands as echo commands, hiding the actual command as well as the pause.

Similarly with the shortcut version:

cmd /k echo echo hello && pause >nul && echo hello && echo ping localhost && pause >nul && ping localhost
Community
  • 1
  • 1
Gerhard
  • 22,678
  • 7
  • 27
  • 43