Batch File Problem

T

Tony P.

Hello,

I have added a batch file to my Startup folder to execute whenever Windows
boots. The batch file works ok but it leaves a blank command (DOS)window on
the screen. The only thing in the command window is a flashing cursor. I
would like close this window using the batch file after the file executes. I
have tried adding an exit command to the batch file but it doesn't seem to
work. When the command window appears on the scrren, the only way to remove
it is to click the X in the upper right corner. I can't enter any commands
in the command window. Is there a way to close the command window in the
batch file?
 
D

Don Phillipson

The batch file works ok but it leaves a blank command (DOS)window on
the screen. The only thing in the command window is a flashing cursor. I
would like close this window using the batch file after the file executes.

You cannot . . .
1. Opening and closing windows is a Windows function.
2. BATch files execute DOS functions in a DOS window.
3. Windows functions cannot be executed in a DOS
environment.
 
P

Pegasus \(MVP\)

Tony P. said:
Hello,

I have added a batch file to my Startup folder to execute whenever Windows
boots. The batch file works ok but it leaves a blank command (DOS)window
on the screen. The only thing in the command window is a flashing cursor.
I would like close this window using the batch file after the file
executes. I have tried adding an exit command to the batch file but it
doesn't seem to work. When the command window appears on the scrren, the
only way to remove it is to click the X in the upper right corner. I can't
enter any commands in the command window. Is there a way to close the
command window in the batch file?

Let's have a look at your batch file.
 
P

Pegasus \(MVP\)

Don Phillipson said:
You cannot . . .
1. Opening and closing windows is a Windows function.

Command Line commands can open and close a Window.
Have a look at the /B switch for the "Start" command.
2. BATch files execute DOS functions in a DOS window.

There is no DOS under Windows and there are no DOS
functions. Perhaps you mean "GUI" applications and
Command Line commands? DOS is an obsolete operating
system. Windows emulates certain components of DOS
but a Command Prompt is definitely not DOS, although
even Microsoft engineers sometimes slip and call it DOS.
3. Windows functions cannot be executed in a DOS
environment.

Not true. You can invoke any command or any GUI
application from a Command Line environment.
 
H

HeyBub

Tony said:
Hello,

I have added a batch file to my Startup folder to execute whenever
Windows boots. The batch file works ok but it leaves a blank command
(DOS)window on the screen. The only thing in the command window is a
flashing cursor. I would like close this window using the batch file
after the file executes. I have tried adding an exit command to the
batch file but it doesn't seem to work. When the command window
appears on the scrren, the only way to remove it is to click the X in
the upper right corner. I can't enter any commands in the command
window. Is there a way to close the command window in the batch file?

Put the word EXIT as the last line of your batch file.
 
T

Tim Slattery

Don Phillipson said:
You cannot . . .
1. Opening and closing windows is a Windows function.
2. BATch files execute DOS functions in a DOS window.
3. Windows functions cannot be executed in a DOS
environment.

But there's no DOS in WinXP. A command console is a 32-bit
environment, and apps that run in this environment can do anything
that a GUI Windows app can do. They can start other apps, they can
show windows themself, they can send messages to GUI applications.

BTW, The "DOS Box" in Win9x was also a 32-bit environment. Command
line apps there could do these things too.

Both environments have the ability to run 16-bit code also.
 
T

Tony P.

Pegasus said:
Let's have a look at your batch file.

This is the batch file in question. The last line of the file has the exit
command but the window stays open.

@echo off
:again
ping www.google.com |find/i"bytes=" > nul && goto Connected
ping localhost -n 60 > nul
goto again

:Connected
"c:\Program Files\Mailwasher\mailwasher.exe"
exit
 
P

Pegasus \(MVP\)

Tony P. said:
This is the batch file in question. The last line of the file has the exit
command but the window stays open.

@echo off
:again
ping www.google.com |find/i"bytes=" > nul && goto Connected
ping localhost -n 60 > nul
goto again

:Connected
"c:\Program Files\Mailwasher\mailwasher.exe"
exit

Your problem is not the batch file or the process in which it runs
but mailwasher.exe itself: It fails to return control to the batch
file until you close it manually. You can easily test this yourself!

To get around the problem, use this code:

:Connected
start "Mail Washer" "c:\Program Files\Mailwasher\mailwasher.exe"

There is no need for the "exit" command - the command
window will close automatically after executing the last
line.
 
T

Tony P.

Adding the Start command corrected the problem. Working ok now.

Thanks to all,
Tony
 
G

Guest

Pegasus (MVP) said:
Your problem is not the batch file or the process in which it runs
but mailwasher.exe itself: It fails to return control to the batch
file until you close it manually. You can easily test this yourself!

To get around the problem, use this code:

:Connected
start "Mail Washer" "c:\Program Files\Mailwasher\mailwasher.exe"

There is no need for the "exit" command - the command
window will close automatically after executing the last
line.

That is right, use 'Call' or, *in this case* use 'Start' to
do_not_wait_on_return of the executable.
You can use Start also for the ping.exe command (that must be a Start /b
then).
And.. when you use Start /b /w here, this will causes the batch to
wait_on_return from the ping command. (btw you don't realy need an extra ping
command, there is no need to pause the loop)

In the batch below you can see also an alternative Pause method (but here it
is just used for delaying the fancy window)

::::] Begin [::::
@echo off
COLOR 9E & echo.&echo.&echo.

echo.Waiting for internet connection.....

::create 'Pause' Function
Set SleepMiliSeconds=start/b/w cscript.exe //NoLogo "%temp%\pause.vbs"
echo.On Error Resume Next>"%temp%\pause.vbs"
echo.Wscript.sleep wScript.Arguments(0)>>"%temp%\pause.vbs"

:again
start/b/w ping.exe -n 2 -w 750 www.google.com|find/i"TTL=" >nul&&^
goto Connected
goto again

:Connected
@cls
COLOR 20 & echo.&echo.&echo.
echo. .....Connected!

start/b "%ProgramFiles%\Mailwasher\mailwasher.exe"

%SleepMiliSeconds% 500
::::] End [::::

\Rems
 
G

Guest

\RemS said:
That is right, use 'Call' or, *in this case* use 'Start' to
do_not_wait_on_return of the executable.
You can use Start also for the ping.exe command (that must be a Start /b
then).
And.. when you use Start /b /w here, this will causes the batch to
wait_on_return from the ping command. (btw you don't realy need an extra ping
command, there is no need to pause the loop)

In the batch below you can see also an alternative Pause method (but here it
is just used for delaying the fancy window)

\Rems

There was a problem in my previous batch the 'Start'-command does not expect
quotes, *but* if you don't use quotes the path-name is invalid because it
contains a space in the name.

To workaround this issue I use 'cmd /c' after Start to call the program. As
you can see in the second last line.

In this batch I use more 'Pause/Wait commands', the effect of this is the
window changes will go smoothly instead of flashing.


::::] Begin [::::
@echo off

::\\Function\\\\\\\\\\\\\
Set WaitMiliSeconds=start/b/w cscript.exe //NoLogo "%temp%\pause.vbs"
echo.On Error Resume Next>"%temp%\pause.vbs"
echo.Wscript.sleep wScript.Arguments(0)>>"%temp%\pause.vbs"
::\\\\\\\\\\\\\\\\\\\\\\\

COLOR 9E
%WaitMiliSeconds% 50

:Loop1
cls & (echo.&echo.&echo.)
%WaitMiliSeconds% 50
echo.Waiting for internet connection...
start/b/w ping.exe -n 2 -w 750 www.google.com|find/i"TTL=" >nul&&^
goto Connected!
%WaitMiliSeconds% 250 & goto Loop1

:Connected!
cls & (echo.&echo.&echo.)
%WaitMiliSeconds% 100
COLOR 20
cls & (echo.&echo.&echo.&echo.&echo.)
%WaitMiliSeconds% 150
echo. .....Connected!
%WaitMiliSeconds% 200
goto Program

:program
Set program=%ProgramFiles%\Mailwasher\mailwasher.exe
If EXIST "%program%",start/b %comspec% /c,"%program%" | CLS
::::] End [::::

\Rems
 
G

Guest

\RemS said:
There was a problem in my previous batch the 'Start'-command does not expect
quotes, *but* if you don't use quotes the path-name is invalid because it
contains a space in the name.

To workaround this issue I use 'cmd /c' after Start to call the program. As
you can see in the second last line.

In this batch I use more 'Pause/Wait commands', the effect of this is the
window changes will go smoothly instead of flashing.


\Rems

ok ok,
The cmd /c brings us back to the fist issue, the dosbox waits till the
program stops.
So we have to find an other solution in order to handle long path/file names
with the Start/b command:

Or.. is it just on my pc?? that I cannot use Start/b to run programs when
the path or file name is not matching the 8.3 notation?. And quotes around
the path are not seem to work needer when using the 'Start/b' command.

Well, I think I now have a final workaround for the problems I have running
the batch on my computer:

::::] Begin [::::

@echo off

::\\Function\\\\\\\\\\\\\
Set WaitMiliSeconds=start/b/w cscript.exe //NoLogo "%temp%\pause.vbs"
echo.On Error Resume Next>"%temp%\pause.vbs"
echo.Wscript.sleep wScript.Arguments(0)>>"%temp%\pause.vbs"
::\\\\\\\\\\\\\\\\\\\\\\\

COLOR 9E
%WaitMiliSeconds% 50

:Loop1
cls & (echo.&echo.&echo.)
%WaitMiliSeconds% 50
echo.Waiting for internet connection...
start/b/w ping.exe -n 2 -w 750 www.google.com|find/i"TTL=" >nul&&goto
Connected!

%WaitMiliSeconds% 250 & goto Loop1

:Connected!
cls & (echo.&echo.&echo.)
%WaitMiliSeconds% 100
COLOR 20
cls & (echo.&echo.&echo.&echo.&echo.)
%WaitMiliSeconds% 150
echo. .....Connected!
%WaitMiliSeconds% 200
goto Program

:program
Set program=%ProgramFiles%\Mailwasher\mailwasher.exe
If EXIST "%program%",(FOR %%g in ("%program%") Do Set $=%%~fsg) ELSE,(GoTo
End)

Start/b %$% &(GoTo End)
:End

::::] End [::::

In the batch as shown above two lines will be broken because they are to
long for the message.

-> restore this line from the batch to just one line :
Start/b/w
ping.exe -n 2 -w 750 www.google.com|find/i"TTL=" >nul&&goto Connected!

-> and, restore this line from the batch to just one line :
If EXIST "%program%",(FOR %%g in ("%program%") Do Set $=%%~fsg)
ELSE,(GoTo End)

\Rems
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top