Ivan Rovelov
Ivan Rovelov

Reputation: 651

Paste but don't execute command in Windows command prompt

My target is to show the Windows command prompt and display a command on the command line without executing it. Therefore, if I want to display the command echo Hello, I want the command prompt to be started and display:

C:\Windows\System32>echo Hello_

... where _ is the blinking cursor waiting for the user to press a key.

To accomplish this, I've tried either to create a shortcut to the Windows command prompt executable, that has its "Target" changed to: C:\Windows\System32\cmd.exe ...

or a bat file containing:

cmd.exe /k ...

... where /k stands for:

/k : Carries out the command specified by string and continues

This makes the command prompt continue to live and not terminate the way the /c switch acts.

Any idea how to achieve this result?

Upvotes: 1

Views: 3022

Answers (2)

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200483

You can't achieve what you want with cmd alone. It could be done with a VBScript, though.

Set sh = CreateObject("WScript.Shell")

sh.Run "%COMSPEC% /k @title MyCmd"
sh.AppActivate "MyCmd"
sh.SendKeys "echo Hello"

Upvotes: 2

Kasnady
Kasnady

Reputation: 2279

I had test and the result success. But dont know is this what you search..

  1. Make a notepad and write

set /p id=hello

  1. save the notepad by .bat format
  2. Make a shorcut and select the notepad you save before
  3. Run the shorcut.

Is that what you wish?

Upvotes: 1

Related Questions