Results 1 to 7 of 7
  1. #1
    Star Lounger
    Join Date
    Jul 2001
    Location
    Edison, New Jersey, USA
    Posts
    89
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Close a CMD window?

    I have an application program that I added to my startup folder. BUT, I need to delay its execution until a Dialogic card and services have been fully initialized (this usually takes anywhere from 30 - 60 seconds). Once started, the application program is designed to continue running in the background and never end.

    I created a .bat routine to call the MS sleep.exe routine to sleep for 60 seconds and then call the application program. I put this routine in the Startup folder.

    This works fine. However it is awkward in that the CMD window that calls the application program stays open.

    I have tried numerous variations of the Start /b (/i) and CMD /c & /k commands. I have attempted a solution with one .bat calling another .bat. I have attempted a solution via a Shortcut using Run Minimized (could not find a "No Window" option).

    I found variations that will exit the window(s), but will not kick off my application. I found variations that will kick off my application, but leave the window(s) open. I have found variations that will Not kick off my application or exit the window(s)... I have not been able to kick off my application and then close the CMD window.

    The process always seems to want to wait for the application to end before it will close the window. In fact, the window will close if I Exit the application, but what good is that when the whole purpose of this particular application is to stay up and active in the background?

    Any ideas?

  2. #2
    Plutonium Lounger Leif's Avatar
    Join Date
    Dec 2000
    Location
    U.K.
    Posts
    14,010
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Close a CMD window?

    There have been threads about this in the past - maybe a search of the whole Lounge might bring up something. Not sure if it applies, but does the thread beginning with <post:=404,048>post 404,048</post:> help at all?

    What operating system(s) is this for?

  3. #3
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    Cincinnati, Ohio, USA
    Posts
    7,089
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Close a CMD window?

    Although I don't see it in the online help (using CMD /?), I seem to recall that you could incorporate a /NOWAIT switch that would allow the CMD process that spawned a child window to NOT wait for processing to complete before continuing on. If I can find some old code examples, I'll share them here (but don't hold your breath).
    -Mark

  4. #4
    Platinum Lounger
    Join Date
    Jan 2001
    Location
    Quedgeley, Gloucester, England
    Posts
    5,333
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Close a CMD window?

    A techique I have used is to start the application and then check in the originating BATch file every <howevermany> seconds with PSLIST whether the process I am interested in has finished running, then terminate.

    You (probably) want to test if the appropriate process has become active (or a service has been started?), then wait some more seconds to make sure, then terminate.

    If you're interested I'll see if I can dig out my code and post it.

    John
    <font face="Script MT Bold"><font color=blue><big><big>John</big></big></font color=blue></font face=script>

    Ita, esto, quidcumque...

  5. #5
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Close a CMD window?

    This may help: in notepad create a file with the following text:
    <pre>dim objShell
    set objShell = createobject("wscript.shell")
    objshell.run "path_to_application_goes_here", 0, false
    </pre>

    (obviously adding the path to your application). Save the file as C:runapp.vbs (or whatever you like.)
    Amend your first batchfile so that it sleeps and then has the line:
    <code>wscript c:runapp.vbs</code>
    and hopefully that should do it.
    Regards,
    Rory

    Microsoft MVP - Excel

  6. #6
    Star Lounger
    Join Date
    Jul 2001
    Location
    Edison, New Jersey, USA
    Posts
    89
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Close a CMD window?

    Thanks for the ideas. Problem solved. I'm just not sure why.... not looking in the right places I suppose. I checked out so many posts, Start /?, cmd /?, MS KB, google searches, etc. I tried so many variation on switches (e.g. /b, /c, /wait, /nowait (does not exist)), etc. and it always came back to the bottom line of not being able to get my application (with its cmd line switches) to start AND get the submitting window to close.

    Turns out that Start "myapp.exe -switch" and Start myapp.exe -switch are VERY different. Probably old news for you folks that work with these things all the time, but for us "unclean", this was a surprize. I thought the quotes would prevent a problem with interpretation, not cause it!

    I'm still confused by things like the /b switch. /? says:
    B . . . Start application without creating a new window. The
    application has ^C handling ignored. Unless the application
    enables ^C processing, ^Break is the only way to interrupt
    the application

    This makes me think I should use /b to start my application without creating a new window. Wrong - had no effect at all. No window was opened with or without the /b; as long as I did not put myapp.exe -switch in quotes. /? says Start will: Starts a separate window to run a specified program or command. I sure thought that using Start would start a separate window to run my program (unless /b supressed that creation). I thought that was one of the differences between using cmd and start; cmd would just execute the command while start would create a new window from which to execute it?

    Well, anyway... For you other newbies having similar problems try:

    Start yourapp.exe -switch
    cls
    exit

    I don't know if I need both cls and exit, but it works and I'm not touching it! Forget the /b and don't use quotes.

    Thanks again, Leif, Mark, and John.

    p.s.
    John, you are correct that a better routine would check the service directly, but I've never had a problem with it starting and it's no big deal to wait a full minute even though the service may have been ready after only 30 seconds. Now I have a nice clean boot process (even if it might have 30 seconds of inefficiency) and I am moving on to my next issue.

  7. #7
    Star Lounger
    Join Date
    Jul 2001
    Location
    Edison, New Jersey, USA
    Posts
    89
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Close a CMD window?

    Rory, evidently I was writing my final post when you submitted this great solution. I suspect my approach is going to die after who-knows-what happens. Your solution looks so clean and easy.... it will be in my next iteration (it'll be my first vbs script!). Thanks again.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •