Programs blocking the current shell

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

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

Re: Programs blocking the current shell

#31 Post by aGerman » 25 Jun 2016 04:21

Maybe there is some kind of launcher incorporated.
What's the outcome of

Code: Select all

@echo off
set "ext=.html"

for /f "tokens=1* delims==" %%i in ('assoc "%ext%" 2^>nul') do (
  for /f "tokens=1* delims==" %%k in ('ftype "%%j"') do echo %%l
)

pause

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

Re: Programs blocking the current shell

#32 Post by misol101 » 25 Jun 2016 04:44

aGerman:

Hehe, this just gets more confusing :)

The output is:

Code: Select all

"C:\Program Files\Internet Explorer\iexplore.exe" %1


But when I launch a html file with e.g. start "" "file.html", Chrome launches!

Edit: and I never use Internet Explorer, I use either Firefox or Chrome.

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

Re: Programs blocking the current shell

#33 Post by aGerman » 25 Jun 2016 05:14

I never understood how the settings for a default browser actually work :?
Could be you have to lookup manually in the registry. Begin with HKEY_CLASSES_ROOT\.html and follow what you find there ...

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Programs blocking the current shell

#34 Post by penpen » 25 Jun 2016 08:41

misol101 wrote: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?
The behaviour should be similar on all windows systems, maybe slightly different on different versions/editions.

But the above is a "normal" multithreading issue.
You should be able to proceed (in your above example) the "banana"-lines by pressing CTRL+BREAK another time.

It's an odd implementation of one input window and (possibly) multiple consumer threads.
I would recommend to avoid using "start /B" until you exactly know what you are doing.

The command shell initially consists of the (main) process "Console Window Host" and one working thread ("Windows Command Processor"; lets name this thread T1).
With "start /B "" banana.bat " you create another thread (=: T2).
When you press CTRL+BREAK then the batch is breaked, with a message, but also the task is switched - so you type into the command shell wheere N/Y is no knwon command switching again to T1, ... .
I hope this is detailed enough, but i also give another example so it might get more obvious:

Use this slightly changed "bananas.bat", if you want to test a bit more:

Code: Select all

@echo off
pause
:LOOP
echo Banana %~1
goto LOOP

No matter what you see type in (without the single quotes; but with the doublequotes):
- 'start /b "" bananas.bat 1' + ENTER
- 'start /b "" bananas.bat 2' + ENTER
- ENTER
- ENTER
- ENTER

After that you should type in the line "start /b "" bananas.bat 2".
This should be the result:

Code: Select all

Z:\>start /b "" bananas.bat 1

Z:\>Drücken Sie eine beliebige Taste . . . start /b "" bananas.bat 2

Z:\>Drücken Sie eine beliebige Taste . . .
Z:\>
Z:\>
banana 1
...
banana 1
Or that:

Code: Select all

Z:\>start /b "" bananas.bat 1

Z:\>Drücken Sie eine beliebige Taste . . . start /b "" bananas.bat 2

Z:\>Drücken Sie eine beliebige Taste . . .
Z:\>
Z:\>
Z:\>
banana 2
...
banana 2

Now you could pause and switch threads using single use of CTRL+BREAK.
After you switched at least one time through all threads you should be able to concurrently run the batch files by using CTRL+C (maybe mutliple times):

Code: Select all

...
Banana 1
Banana 2
Banana 1
Banana 2
Banana 1
Banana 2
Banana 1
Banana 2
...


If you want to break all batch files, then you have to press CTRL+BREAK and hold it, until the display shows some eror message (could be various ones).
But the tasks are still running.
If your doskey is enabled, then you should be able to switch between the 'start /b ...' lines using CURSOR_IP/CURSOR_DOWN.
if doskey doesn't show alternatives it is one of the child threads ("Windows Command Processor"), and you could terminate them by typing 'exit' (+RETURN).


penpen

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

Re: Programs blocking the current shell

#35 Post by misol101 » 25 Jun 2016 09:05

penpen wrote:The command shell initially consists of the (main) process "Console Window Host" and one working thread ("Windows Command Processor"; lets name this thread T1).
With "start /B "" banana.bat " you create another thread (=: T2).
When you press CTRL+BREAK then the batch is breaked, with a message, but also the task is switched - so you type into the command shell wheere N/Y is no knwon command switching again to T1, ...


Thanks penpen, that makes sense of the behaviour then that the task switches after Ctrl-Break.

So, basically, my example was meant to show that /B can easily lead to all kinds of (expected) strangeness due to multi-threading, and I would agree that /B should be avoided unless there is a very specific use case and you know exactly what will happen due to concurrent threads. In my general case (for the listb file explorer), it's the opposite, i.e. I don't know which program will run, and also not what it's supposed to accomplish. So, better stay away from /B :)

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

Re: Programs blocking the current shell

#36 Post by foxidrive » 26 Jun 2016 14:11

misol101 wrote: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?

misol101 wrote: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...


I wasn't able to follow up for some time but No, it doesn't behave like that here.

Here is my test script:

Code: Select all

@echo off
(
echo @echo off
echo :LOOP
echo echo Banana
echo goto LOOP
)>banana.bat
start /B "" "banana.bat"


This is the result
Image

misol101 wrote: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.

That is what I wrote to notify Google of, and showed in my last post.

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

Re: Programs blocking the current shell

#37 Post by misol101 » 26 Jun 2016 15:22

foxidrive wrote:I wasn't able to follow up for some time but No, it doesn't behave like that here.


Ok, interesting. Perhaps it's different on different Windows versions. Did you try running it a few times in a row? Still no weird behaviour? I found that it behaves differently, usually it runs the way I described it before [1], but sometimes it quits, but without actually waiting for response to whether I want to break or not [2]. I think it has to do with the concurrent threads and their task switching, i.e. sometimes the new thread gets the Ctrl-Break (that would be behavior [1]) and sometimes the calling thread gets it [2].

After running it a few times (usually just one), my shell is definitely messed up.

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Programs blocking the current shell

#38 Post by penpen » 26 Jun 2016 18:22

foxidrive wrote:I wasn't able to follow up for some time but No, it doesn't behave like that here.

Here is my test script:

Code: Select all

@echo off
(
echo @echo off
echo :LOOP
echo echo Banana
echo goto LOOP
)>banana.bat
start /B "" "banana.bat"
I assume you are starting the above batch by doubleclick on the icon (or similar).
In that case the console has no primary working thread that handles command line input, because it processes the above batch, resulting in capture of CTRL+BREAK from within that batch context.

To see the messed up console, you have to start cmd.exe first, and enter the line "start /b "" "banana.bat"" manually.
(Alternatively my "bananas.bat" example.)

(Tested on my win xp (VirtualBox), and win 8.1 with the difference (the two results) described in my last post:
the first was win 8.1 the second corresponds to win xp.)


penpen

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

Re: Programs blocking the current shell

#39 Post by foxidrive » 27 Jun 2016 21:04

penpen wrote:I assume you are starting the above batch by doubleclick on the icon (or similar).
In that case the console has no primary working thread that handles command line input, because it processes the above batch, resulting in capture of CTRL+BREAK from within that batch context.

To see the messed up console, you have to start cmd.exe first, and enter the line "start /b "" "banana.bat"" manually.
(Alternatively my "bananas.bat" example.)


You're right penpen. I press enter in total commander to launch the script and doing as you outlined does cause issues. But I giggled when testing it because only super-nerds or no-hopers would type a start command like that at the cmd prompt. :D

It's rare for me to use a cmd prompt for any serious work, I only open one for testing. Total commander puts everything at my fingertips and it gives me my favourite text editor on cue too.

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

Re: Programs blocking the current shell

#40 Post by misol101 » 28 Jun 2016 03:57

foxidrive wrote:I giggled when testing it because only super-nerds or no-hopers would type a start command like that at the cmd prompt. :D

It's rare for me to use a cmd prompt for any serious work, I only open one for testing. Total commander puts everything at my fingertips and it gives me my favourite text editor on cue too.


Totally. I have a similar issue with my other favorite forum, mechanicstips.com, where people go on and on about choke linkages and drain plugs. I mean, why get dirty on the floor like some greasemonkey when you can just *drive the car*? For some reason, the other people hanging out at mechanicstips.com don't seem to agree, they even say it matters in which order I do things when I fiddle around with the engine!

And don't even get me started on bashtips.com :mrgreen:

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Programs blocking the current shell

#41 Post by penpen » 28 Jun 2016 06:14

foxidrive wrote:You're right penpen. I press enter in total commander to launch the script and doing as you outlined does cause issues. But I giggled when testing it because only super-nerds or no-hopers would type a start command like that at the cmd prompt. :D
You could provoke that error in various ways; the above method is only the simplest.
If you use the "banana.bat" from misol101, and the following scripts, then you should provoke the issue by just executing "test.bat" (in any way).

"startBanana.bat":

Code: Select all

@echo off
start /B "" "banana.bat"

"test.bat";

Code: Select all

@echo off
cmd /K "startBanana.bat"


penpen

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

Re: Programs blocking the current shell

#42 Post by foxidrive » 29 Jun 2016 03:52

penpen wrote:If you use the "banana.bat" from misol101, and the following scripts, then you should provoke the issue by just executing "test.bat" (in any way).


Granted, penpen, though it is far different in scope.

Post Reply