Open (second) cmdprompt, execute command and stay open?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
pstein
Posts: 125
Joined: 09 Nov 2011 01:42

Open (second) cmdprompt, execute command and stay open?

#1 Post by pstein » 07 Apr 2017 03:19

From within a dos batch file I want to open a (second) command prompt, then execute a command in it and finally let the second cmdprompt stay open.
The first cmdprompt should meanwhile continue to run.

The following (simplified) code does NOT work (under 64bit Win7):

Code: Select all

set drive=D
set logfile=mylogfile.log
start "" C:\WINDOWS\system32\cmd.exe /c "type %drive%:\%logfile%"
echo text after second cmdprompt creation


How do I have to modify it to get it working?

Thank you
Peter

npocmaka_
Posts: 512
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Re: Open (second) cmdprompt, execute command and stay open?

#2 Post by npocmaka_ » 07 Apr 2017 05:56

try with :

Code: Select all

start "" C:\WINDOWS\system32\cmd.exe /k "type %drive%:\%logfile%"

pstein
Posts: 125
Joined: 09 Nov 2011 01:42

Re: Open (second) cmdprompt, execute command and stay open?

#3 Post by pstein » 08 Apr 2017 04:46

It works. Thank you.
But two more problems arise now:

1.) The opened Command prompt shows topmost a message:

"Not enough storage is available to process this command"

This warning/error appears even if I pass a simple command like "echo hello"

Why?
How do I increase storage?

2.) When I scroll back in this new command prompt (with arrow up) then the previous (first) command is not shown

How can I enable history?

Peter

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Open (second) cmdprompt, execute command and stay open?

#4 Post by aGerman » 08 Apr 2017 05:05

You should really explain your goal with a real example. To be honest I have no idea what you're trying to do without using a crystal ball.

Some general rules
- START creates a new cmd.exe process.
- You can't attach more than one console window to the same process.
- You can attach the same console window to more than one process (e.g. using START /B).
- You can't remote control another cmd.exe process.

Steffen

ShadowThief
Expert
Posts: 1163
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Open (second) cmdprompt, execute command and stay open?

#5 Post by ShadowThief » 08 Apr 2017 05:06

Sounds like you have basically 0 free space in D:, which is horrifying to think about. Deleting files or moving them to another drive are your only options.

When you run the cmd command, you are opening a brand new instance of the command prompt. There is no previous history to show; what you're asking for is impossible by design.

pstein
Posts: 125
Joined: 09 Nov 2011 01:42

Re: Open (second) cmdprompt, execute command and stay open?

#6 Post by pstein » 09 Apr 2017 00:14

ShadowThief wrote:Sounds like you have basically 0 free space in D:, which is horrifying to think about. Deleting files or moving them to another drive are your only options.

When you run the cmd command, you are opening a brand new instance of the command prompt. There is no previous history to show; what you're asking for is impossible by design.


I have more than 100GB free on my D: partition and I have 8 GB memory. That should be sufficient.
Yes, I want to open a brand new (independent) command prompt.

Even simpler: Think of the following command

Code: Select all

start "" C:\WINDOWS\system32\cmd.exe /k "echo hello"


The /k parameter passes a (=the first) command (here: echo hello) to this new command prompt for initial execution.
So there should be at least ONE command in history.

Using C:\WINDOWS\SysWOW64\cmd.exe instead of C:\WINDOWS\system32\cmd.exe does not help

So is there really no solution for the two problems?

Peter

Aacini
Expert
Posts: 1885
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Open (second) cmdprompt, execute command and stay open?

#7 Post by Aacini » 09 Apr 2017 04:13

pstein wrote:
. . .

Even simpler: Think of the following command

Code: Select all

start "" C:\WINDOWS\system32\cmd.exe /k "echo hello"


The /k parameter passes a (=the first) command (here: echo hello) to this new command prompt for initial execution.
So there should be at least ONE command in history.

. . .

Peter

No. You are forgetting a fundamental point about the "command history": it is comprised of commands typed at the command-prompt. If you type previous line, then the whole "start ..." command is stored in the history of original cmd.exe, but in the new cmd.exe session there is not a single command typed at the command prompt!

If previous line is in a Batch file and you type its name instead, then the "start ..." command is not stored in the command history, but the line used to start the Batch file. The history is not comprised of "executed commands".

I suggest you to read this jeb topic about this point.

Antonio

Post Reply