Re: Batch File Problem - Batch File Enclosed



"\RemS" wrote:

"Pegasus (MVP)" wrote:

"Tony P." <noone@xxxxxxxxxxxxxxxxx> wrote in message
news:ueaHJ49GIHA.484@xxxxxxxxxxxxxxxxxxxxxxx
Pegasus (MVP) wrote:
"Tony P." <noone@xxxxxxxxxxxxxxxxx> wrote in message
news:Osr25e6GIHA.4592@xxxxxxxxxxxxxxxxxxxxxxx
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?

--
Thanks,
Tony
For replies, please correct my email address.


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



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)

\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
.



Relevant Pages

  • Re: batch question
    ... window at great speed, without being executed. ... all I want is for the command to work inside a command prompt window. ... Your original batch file had two lines. ... you fell into a well-known trap: you are not executing ping.exe ...
    (microsoft.public.windowsxp.general)
  • Re: xp_cmdshell default path (system32) problem
    ... building a batch file in code and then ... it will NOT actually execute the delete if the patch I supply is not valid. ... I'm use xp_cmdShell to execute "erase" command like ...
    (microsoft.public.sqlserver.programming)
  • Re: Perfmon and batch file
    ... > event viewer and run command file. ... > but no execute the cmd file or execute it but not execute the ... You are probably making some assumptions in your batch file ... @echo off ...
    (microsoft.public.windows.server.general)
  • Re: Execute a batch file and wait for it to complete
    ... and until I manually close the console. ... Starts a separate window to run a specified program or command. ... If it is an internal cmd command or a batch file then ...
    (comp.lang.fortran)
  • Build instructions for loadcepc.exe
    ... Build instructions for loadcepc.exe ... a standard cmd.exe window. ... Execute the batch file setupenv.bat: ... command promt ...
    (microsoft.public.windowsce.platbuilder)

Quantcast