Page 1 of 1
Open (second) cmdprompt, execute command and stay open?
Posted: 07 Apr 2017 03:19
by pstein
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
Re: Open (second) cmdprompt, execute command and stay open?
Posted: 07 Apr 2017 05:56
by npocmaka_
try with :
Code: Select all
start "" C:\WINDOWS\system32\cmd.exe /k "type %drive%:\%logfile%"
Re: Open (second) cmdprompt, execute command and stay open?
Posted: 08 Apr 2017 04:46
by pstein
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
Re: Open (second) cmdprompt, execute command and stay open?
Posted: 08 Apr 2017 05:05
by aGerman
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
Re: Open (second) cmdprompt, execute command and stay open?
Posted: 08 Apr 2017 05:06
by ShadowThief
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.
Re: Open (second) cmdprompt, execute command and stay open?
Posted: 09 Apr 2017 00:14
by pstein
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
Re: Open (second) cmdprompt, execute command and stay open?
Posted: 09 Apr 2017 04:13
by Aacini
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