Programs blocking the current shell

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
misol101
Posts: 475
Joined: 02 May 2016 18:20

Re: Programs blocking the current shell

#16 Post by misol101 » 24 Jun 2016 11:43

aGerman wrote:What happens if you only close the tab with your html file instead of the whole Chrome window?


Nothing, the cmd window is frozen.

misol101
Posts: 475
Joined: 02 May 2016 18:20

Re: Programs blocking the current shell

#17 Post by misol101 » 24 Jun 2016 12:12

If anybody could reveal the mysteries of /B switch, that would be greatly appreciated too :)

An example, banana.bat:

Code: Select all

:LOOP
echo Banana
goto LOOP


start /B "" "banana.bat"

As expected from the "start" documentation, Ctrl-C does not work to break. I press Ctrl-Break, the program stops and asks if I want to break. I press 'y', the shell says there is no command y, then "quits". Any command after this gives me back the question if I want to break the program, i.e. the cmd shell is all messed up...

start /B /WAIT "" "banana.bat"

A bit more promising. Again, Ctrl-C does not work. However, Ctrl-Break works as expected this time, and cmd shell seems "normal" afterwards... except my cmd history is gone. I then have to write "exit" and then I'm back to my old shell, with history back. (Also, when running with /WAIT, my external exe files calling getch to get input gets the keys as expected, unlike when running with /B without /WAIT)

BUT... unfortunately, when running with the /WAIT switch, cmd is again frozen if I run Chrome that way :( so, no good in this case

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Programs blocking the current shell

#18 Post by foxidrive » 24 Jun 2016 15:19

misol101 wrote:I have run into something confusing. Some programs, when run from a batch program, seems to block forever, even after the program quits! I am then forced to close down the cmd window, Ctrl-C/Z/break do not work.

Code: Select all

::"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" (1)
::call "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" (2)
::cmd /C "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" (3)
::start C:\Program Files (x86)\Google\Chrome\Application\chrome.exe (4)
::start "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" (5)
::start cmd /C "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" (6)
start /B cmd /C "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" (7)



This is a longish thread - but in essence the batch will stop because it is missing "" after the start keyword.

The title of the start command is the first double quoted term, and this is a common problem for people to encounter.

Adding "" gives the start command an empty title.

misol101
Posts: 475
Joined: 02 May 2016 18:20

Re: Programs blocking the current shell

#19 Post by misol101 » 24 Jun 2016 15:25

foxidrive wrote:This is a longish thread - but in essence the batch will stop because it is missing "" after the start keyword.


No, surprisingly it runs as expected, the problem is another (as the thread explains). (though I have learned from this thread that the first argument to "start" should be "" (or title). That must be one of the most stupid argument design choices I have seen, but that's another question...)
Last edited by misol101 on 24 Jun 2016 15:45, edited 1 time in total.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Programs blocking the current shell

#20 Post by foxidrive » 24 Jun 2016 15:29

misol101 wrote:No, surprisingly it runs as expected, the problem is another (as the thread explains)


Are you sure? I edited my post as you were replying.

misol101 wrote:Case (5): A new cmd window is opened, and nothing else happens (why is it like this?)

This is what is in your question and what I was addressing.

misol101
Posts: 475
Joined: 02 May 2016 18:20

Re: Programs blocking the current shell

#21 Post by misol101 » 24 Jun 2016 15:31

foxidrive wrote:
misol101 wrote:Case (5): A new cmd window is opened, and nothing else happens (why is it like this?)

This is what is in your question and what I was addressing.


Ok, that was a side question, not the main one. But agreed, you did answer that. Thank you.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Programs blocking the current shell

#22 Post by foxidrive » 24 Jun 2016 16:02

misol101 wrote:Ok, that was a side question, not the main one. But agreed, you did answer that. Thank you.


No worries. It seems that the question must have morphed.
I won't follow the thread and this has probably been mentioned, but the issue you see on the first command in the initial question is with Chrome.

If you try the same thing with Firefox it will release the batch script and is what all multi-threaded GUI programs should do.

Code: Select all

"C:\Program Files\Google\Chrome\Application\chrome.exe"


Code: Select all

"c:\Program Files\Mozilla Firefox\firefox.exe"

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

Re: Programs blocking the current shell

#23 Post by aGerman » 24 Jun 2016 16:14

I'm at my wits end too. No idea what happens with Chrome here.

Did you have a look into the Task Manager and were all Chrome processes terminated?

misol101
Posts: 475
Joined: 02 May 2016 18:20

Re: Programs blocking the current shell

#24 Post by misol101 » 24 Jun 2016 16:23

foxidrive wrote:...the issue you see on the first command in the initial question is with Chrome.

If you try the same thing with Firefox it will release the batch script and is what all multi-threaded GUI programs should do.


Agreed, they really should! :) The issue is within my listb file explorer though, so I can't really "choose" which programs the user runs, Chrome is just an example of a faulty one.

We have concluded that: start "" "program" works to solve the "freeze" (well, actually it "solves" it by running in a different process), but the problem is that I do not want a new cmd window to open in the case of running bat files or exe files that write to the console (and I can not know which files the user runs, and I can not know if an exe file will write to the console or not). Essentially, I want the functionality of: call "program" but it does not work in all cases due to some programs apparently not reporting back when they quit.

Ok, I hope that makes sense. I made a mess of this thread :roll:

aGerman wrote:Did you have a look into the Task Manager and were all Chrome processes terminated?


Not really. I should, though really the problem is not so much with Chrome(maybe), but rather that if one program freezes like that, maybe others do too. In a file explorer, that is not good.

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

Re: Programs blocking the current shell

#25 Post by aGerman » 24 Jun 2016 16:35

In a file explorer, that is not good.

Um ... from my point of view file explorers should run them rather asynchronously. At least I would complain if the Windows Explorer wouldn't ... :wink:

misol101
Posts: 475
Joined: 02 May 2016 18:20

Re: Programs blocking the current shell

#26 Post by misol101 » 24 Jun 2016 16:41

aGerman wrote:Um ... from my point of view file explorers should run them rather asynchronously. At least I would complain if the Windows Explorer wouldn't ... :wink:


Haha, yes, true of course. The thing is, I don't really care if they run asynchronously or not for listb, but yes, I guess it is better they do. And I'm fine with having everything run asynchronously, but the remaining issue is I don't want new cmd windows to open when running bat and console exe files. And start does that, and start /b is all messed up.

misol101
Posts: 475
Joined: 02 May 2016 18:20

Re: Programs blocking the current shell

#27 Post by misol101 » 24 Jun 2016 16:47

I think my "solution" to this will be to use: call "file" for bat and exe files, and: start "" "file" for all other extensions. This could still lead to freezes if the user actively browsed to e.g. the Chrome folder and started the executable, but it's pretty unlikely. It's much more likely Chrome will be run when opening a html file or similar, ie through file associations.

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

Re: Programs blocking the current shell

#28 Post by aGerman » 24 Jun 2016 17:04

I don't want new cmd windows to open when running bat and console exe files.

I fear you have to bite the bullet. Any other file explorer would open them in a new window as well.

Otherwise you have to distinguish. File extensions .bat and .cmd run in a console window. For PE files you have to write another tool: http://stackoverflow.com/questions/7739571/how-to-tell-if-a-windows-pe-file-is-a-console-subsystem-or-a-windows-subsystem-p
For JScript and VBScript files you have to read the registry settings in order to determine whether they run in cscript or wscript.
Pretty complicated and probably unnecessary, isn't it :?

I think my "solution" to this will be to use: call "file" for bat and exe files, and: start "" "file" for all other extensions.

Give it a go. Sounds OK to me.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Programs blocking the current shell

#29 Post by foxidrive » 24 Jun 2016 17:53

misol101 wrote:start /B "" "file.bat"

has the same side effects (and the side effect is that my external exe file, which runs getch to get key input, no longer gets any input).

I've not seen this happening with other utilities and using /b with start. Have you experienced this with any other batch script?
misol101 wrote:The issue is within my listb file explorer though, so I can't really "choose" which programs the user runs, Chrome is just an example of a faulty one.

A realistic viewpoint here is that some programs are broken and just behave incorrectly. This is a flaw in Chrome that just hasn't been picked up, or is being ignored. Your listb is not at fault here.

Just googled a bit - this problem was evident at least three years ago.
http://stackoverflow.com/questions/1434 ... mmand-line

I reported the problem to Google. Someone may get 3 minutes fun out fixing this. :)

Launch this batch script in Windows where Chrome is not running and Chrome will not release the batch script. The echo line does not appear, unless Chrome is already running.

@echo off
"C:\Program Files\Google\Chrome\Application\chrome.exe"
echo Now on to other batch aspects
pause


A multi-threaded GUI program should not behave like this.

misol101
Posts: 475
Joined: 02 May 2016 18:20

Re: Programs blocking the current shell

#30 Post by misol101 » 24 Jun 2016 18:10

foxidrive wrote:I've not seen this happening with other utilities and using /b with start. Have you experienced this with any other batch script?


At the top of this page(page 2) I write about some odd behaviour that is caused by running start /b with a very simple example file called banana.bat. Does it behave the same way for you?

foxidrive wrote:Just googled a bit - this problem was evident at least three years ago.
http://stackoverflow.com/questions/1434 ... mmand-line


Thanks for googling! Well, yes, probably it's an uncommon problem at least. I have only seen it with Chrome yet. It should also be noted that if Chrome is *already running* when launching e.g. a html file, then there is no blocking. The problem happens only if Chrome is not running before.

Post Reply