How to open a batch file and execute a command AFTER opening command prompt

4

I am trying to create a batch file that first opens command prompt and then executes "prompt $t$gEnter Command Here$g". I have tried starting it with "%windir%\system32\cmd.exe" and then using "&&" to run the "prompt $t$gEnter Command Here$g" afterwards but I cannot get it to work. My reason for doing this is to have command prompt open through the batch file and display "prompt $t$gEnter Command Here$g" as the return. So it would say "{Time}> Enter Command Here>" for each return. Please help.

AbjectCone047

Posted 2015-06-26T06:27:15.547

Reputation: 41

Answers

1

The Start verb will open cmd in a new window. This works for me in a .bat:

start cmd /K PROMPT $t$gEnter Command Here$g

the /K will keep the cmd window open after running the prompt command, so you can use the shell.

Just save it in a batch file, and invoke by double-click or in another command window.

Frank Thomas

Posted 2015-06-26T06:27:15.547

Reputation: 29 039

Wonderful. would you like to mark the answer as accepted? – Frank Thomas – 2015-06-30T16:56:59.343

he has slept before marking answer as accepted. – Vishal Kumar Sahu – 2017-10-08T20:10:57.310

2indeed. after two years, he must be well rested. – Frank Thomas – 2017-10-08T22:12:15.430

How do we wait for 5 sec and then enter some command after prompt. – Rupesh – 2019-01-02T13:56:25.340

0

How do I open a batch file and execute a command after opening command prompt

Create a file called myprompt.cmd:

@echo off
prompt $t$gEnter Command Here$g

Run it:

C:\test>myprompt

 7:43:35.72>Enter Command Here>dir
 Volume in drive C has no label.
 Volume Serial Number is C8D0-DF1E

 Directory of C:\test

26/06/2015  07:43    <DIR>          .
26/06/2015  07:43    <DIR>          ..
26/06/2015  07:40                42 myprompt.cmd
               1 File(s)             42 bytes
               2 Dir(s)  87,332,958,208 bytes free

 7:43:38.34>Enter Command Here>

DavidPostill

Posted 2015-06-26T06:27:15.547

Reputation: 118 938