batch execution

May 12, 2014
31
0
#1
I have 3 commands I would like to execute in a single alias or btm file.

Command 1: rename fileA fileB
Command 2: http://<my ISP website>
Command 3: rename fileB fileA

The trick is that I don't want command 3 to be executed until command 2 has completed - i.e., the browser has been closed. How can I do this?
 
#2
In a BTM, something like
Code:
ren fileA fileB
start /wait path_to_browser_exe http://...
ren fileB fileA
But if the browser is already opened and the URL is opened via DDE, I don't think the "/wait" will work.
Or maybe ...
Code:
ren fileA fileB
http://...
delay 3
do while isapp path_to_browser_exe
  delay 1
enddo
ren fileB fileA
... or something like that.
 
May 12, 2014
31
0
#3
In a BTM, something like
Code:
ren fileA fileB
start /wait path_to_browser_exe http://...
ren fileB fileA
But if the browser is already opened and the URL is opened via DDE, I don't think the "/wait" will work.
Or maybe ...
Code:
ren fileA fileB
http://...
delay 3
do while isapp path_to_browser_exe
  delay 1
enddo
ren fileB fileA
... or something like that.
The problem seems to be in the btm file, not the alias. Here's exactly what I'm trying to do (don't ask why the file rename; it works)

hosts is the alias that renames my hosts file to hosts.xxx if hosts.xxx doesn't exist, and the reverse if hosts.xxx exists.
https://myaccount.shaw.ca
hosts

as an alias, the first two commands work fine, but leave the hosts.xxx file in place of the regular hosts file.

If I separate the commands by putting them into a btm file, "hosts" is the only command that gets executed. Does the fact that "hosts" is an alias in a btm file fork the process out of the btm file, thus circumventing the rest of the btm file?

I just want to come up with a way to rename my hosts file, go to my ISP's website, and then when the browser closes, restore the original hosts file. As it stands now I have an alias that executes the first two commands, but I have to manually execute the hosts alias again to restore the original hosts file.
 
#4
I don't think the name of the alias is a problem. I don't know what your alias does (and I'm not recommending mine) but this works here:
Code:
alias hosts if exist v:\hosts (ren v:\hosts hosts.xxx) else (ren v:\hosts.xxx hosts)
hosts
start /wait firefox http://google.com
echo FireFox has closed
hosts
unalias hosts
and it produces this output.
Code:
v:\> waittest.btm
V:\hosts -> V:\hosts.xxx
  1 file renamed
FireFox has closed
V:\hosts.xxx -> V:\hosts
  1 file renamed
 
#5
The firefox.exe command just passes it's command line parameters to a browser master process an then immediately returns. So there is no chance to make your batch wait until you close the window or process. Not even start /wait will help.
 
#6
That's correct. START /WAIT will not work if the browser is already running.

Perhaps you could loop while the window (the firefox tab) exists. Here, while replying to this thread with other firefox tabs open,
Code:
v:\> if iswindow "batch*Take Command*" echo yes
yes
 
May 12, 2014
31
0
#7
The firefox.exe command just passes it's command line parameters to a browser master process an then immediately returns. So there is no chance to make your batch wait until you close the window or process. Not even start /wait will help.
You're wrong - it DOES work.
 
May 12, 2014
31
0
#8
I don't think the name of the alias is a problem. I don't know what your alias does (and I'm not recommending mine) but this works here:
Code:
alias hosts if exist v:\hosts (ren v:\hosts hosts.xxx) else (ren v:\hosts.xxx hosts)
hosts
start /wait firefox http://google.com
echo FireFox has closed
hosts
unalias hosts
and it produces this output.
Code:
v:\> waittest.btm
V:\hosts -> V:\hosts.xxx
  1 file renamed
FireFox has closed
V:\hosts.xxx -> V:\hosts
  1 file renamed
Thank you! This worked perfectly.

However, my ISP has apparently fixed their login page which necessitated this workaround. No longer need to rename the hosts file.
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
3,575
46
Albuquerque, NM
prospero.unm.edu
#10
Am I? This is what the TCC help says:
Code:
Due to the way Windows handles URLs, you cannot wait for the browser to finish when you
enter an HTTP: URL at the prompt.
In this situation, TCC always displays the next prompt immediately.
So who is wrong?
I haven't tested the scenario myself; I can't speak to Mr. Hall's assertion. But the doc snippet you quote seems to be about entering a URL at the prompt -- not starting a URL with the START command.