When run %ComSpec% /c, window is not close automatically?

English support forum

Moderators: Hacker, petermad, Stefan2, white

Post Reply
Hurdet
Power Member
Power Member
Posts: 716
Joined: 2003-05-10, 18:02 UTC

When run %ComSpec% /c, window is not close automatically?

Post by *Hurdet »

When run:
%ComSpec% /c "C:\Program Files\TotalCmd\TOTALCMD64.EXE"
secondary session after execution is not Closed
I have to close TOTALCMD64.EXE to hit.
why?
User avatar
Hacker
Moderator
Moderator
Posts: 13144
Joined: 2003-02-06, 14:56 UTC
Location: Bratislava, Slovakia

Re: %ComSpec% /c not close

Post by *Hacker »

[mod="Hacker"]Moved to the English forum.[/mod]
Mal angenommen, du drückst Strg+F, wählst die FTP-Verbindung (mit gespeichertem Passwort), klickst aber nicht auf Verbinden, sondern fällst tot um.
User avatar
Hacker
Moderator
Moderator
Posts: 13144
Joined: 2003-02-06, 14:56 UTC
Location: Bratislava, Slovakia

Re: %ComSpec% /c not close

Post by *Hacker »

Hurdet,
It's because CMD does not close as long as the invoked program is running. Try:

Code: Select all

%ComSpec% /c notepad
Roman
Mal angenommen, du drückst Strg+F, wählst die FTP-Verbindung (mit gespeichertem Passwort), klickst aber nicht auf Verbinden, sondern fällst tot um.
User avatar
Stefan2
Power Member
Power Member
Posts: 4281
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Re: %ComSpec% /c not close

Post by *Stefan2 »

Hurdet wrote: 2020-03-19, 18:55 UTC When run:
%ComSpec% /c "C:\Program Files\TotalCmd\TOTALCMD64.EXE"
secondary session after execution is not Closed
I have to close TOTALCMD64.EXE to hit.
why?

If I understood you correctly, you want to execute an application via ComSpec without keeping the black DOS window open?

Try
cmd /c START "" "C:\Program Files\TotalCmd\TOTALCMD64.EXE"

Or just "C:\Program Files\TotalCmd\TOTALCMD64.EXE" alone





HTH?
Hurdet
Power Member
Power Member
Posts: 716
Joined: 2003-05-10, 18:02 UTC

Re: %ComSpec% /c not close

Post by *Hurdet »

Hacker wrote: 2020-03-19, 19:15 UTC It's because CMD does not close as long as the invoked program is running. Try:

Code: Select all

%ComSpec% /c notepad
It is not correct.
"/C Carries out the command specified by the string and then terminates"
try:
%ComSpec% /c write.exe
I assume that the recent ComSpec may have particular requirements to function properly.
I assume also that this is correlate a this.
Stefan2 wrote: 2020-03-19, 19:32 UTC If I understood you correctly, you want to execute an application via ComSpec without keeping the black DOS window open?
I know this but I am interested in investigating the specific problem because I suspect it may also have other repercussions.
Hacker wrote: 2020-03-19, 19:14 UTC Moved to the English forum.
ty, excuse me.
User avatar
Dalai
Power Member
Power Member
Posts: 10024
Joined: 2005-01-28, 22:17 UTC
Location: Meiningen (Südthüringen)

Re: %ComSpec% /c not close

Post by *Dalai »

2Hurdet
write.exe is only a wrapper that calls wordpad.exe and then terminates itself - see Windows Task Manager. That's why %ComSpec% /c write.exe works how you expect it, while %ComSpec% /c notepad.exe does not.

And, BTW, something like "%ComSpec% /c totalcmd.exe" can be classified as "useless use of CMD" (quote in the style of "useless use of cat" or "useless use of ls" known from Linux).

Regards
Dalai
#101164 Personal licence
Ryzen 5 2600, 16 GiB RAM, ASUS Prime X370-A, Win7 x64

Plugins: Services2, Startups, CertificateInfo, SignatureInfo, LineBreakInfo - Download-Mirror
Hurdet
Power Member
Power Member
Posts: 716
Joined: 2003-05-10, 18:02 UTC

Re: %ComSpec% /c not close

Post by *Hurdet »

I am not full convinced, try:
%ComSpec% /c "C:\Program Files\Firefox\Firefox.exe"
%ComSpec% /c "ProcessHacker.exe"
%ComSpec% /c explorer.exe
%ComSpec% /c "c:\Program Files (x86)\Internet Explorer\iexplore.exe"
otherwise "/ C" should work only in batch dos? but it is not speciefed in command dos help.
User avatar
Dalai
Power Member
Power Member
Posts: 10024
Joined: 2005-01-28, 22:17 UTC
Location: Meiningen (Südthüringen)

Re: %ComSpec% /c not close

Post by *Dalai »

2Hurdet
%ComSpec% /C works as it's supposed to in every case. If it wouldn't, people would have complained about it for many years, not just in conjunction with TC. As soon as the launched process ends, %ComSpec% returns control to the user, or in case of /C it closes itself. When the launched process is a wrapper that creates another process by itself (and terminates itself after that), it closes immediately. That's just how it works and how it's supposed to work.

If you're in doubt, check for the "Parent" process in Process Hacker. If it doesn't exist anymore - e.g. with firefox.exe - the process launched by %ComSpec% terminated itself, hence /C closes the window. There are also other situations where a process tells another process to spawn a new process. That's the case for explorer.exe, which tells svchost.exe to run something like "C:\Windows\explorer.exe /factory,{ceff45ee-c862-41de-aee2-a022c81eda92} -Embedding" - complicated stuff that I don't understand (but I don't need to).

If you want to avoid the black CMD window, just call the program's EXE directly, or use %ComSpec% /C start "" "path\to\programexe" as already suggested by Stefan2.

Regards
Dalai
#101164 Personal licence
Ryzen 5 2600, 16 GiB RAM, ASUS Prime X370-A, Win7 x64

Plugins: Services2, Startups, CertificateInfo, SignatureInfo, LineBreakInfo - Download-Mirror
Hurdet
Power Member
Power Member
Posts: 716
Joined: 2003-05-10, 18:02 UTC

Re: %ComSpec% /c not close

Post by *Hurdet »

ok, you convinced me.
I try ShellExecute.
Post Reply