Results 1 to 6 of 6
  1. #1
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Hatsukaichi, Hiroshima, Japan
    Posts
    904
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Resuming a batch file after application closes (XPPro SP2)

    Hello,

    I have another question about batch files. I'd like to have a batch file that pauses after launching Word 97 and then when I close Word 97 resumes. Is this possible? What I want to be able to do is to get the batchfile to move a newly created document to a specific location. I realise I could run the batchfile after closing down Word but if there was an automated process I think that could be useful for various tasks.

    Thanks,

    Chris (Hunt)

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

    Re: Resuming a batch file after application closes

    You can call another process and have the batch script halt while it is open, but there is no viable way of returning information to the script. You would have to write your own exception handling to check for the new file(s) and then move them, because anything could happen while the secondary process is open.

    In short, I don't think there's a reliable way to do what you want with a BATch file.
    -Mark

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

    Re: Resuming a batch file after application closes

    What I meant by "returning information to the script" is that there are no mechanisms to tell the BATch file what is happening. Word MUST be exited in order for control to pass back to the script. What if it the document was not saved successfully (or at all)? What if Word hung? The START command using the /W switch works better for sub-processing that does not require user input. In one of my many pasts we used this method to scrub text, calling a small EXE or similar to do the deed and then terminate. The scenario in the original post involves a large external application and is dependent on user input to succeed, not an ideal use for BATch files.

    I think a better solution would be to create a script that moves/renames documents in a given folder (or folders), in a polling fashion. It could run continuously using the WAIT command or via task scheduler, and would not be dependent on external variables. If there are documents present, they're processed, if not, the script sleeps. It could even generate a log of its activity and shoot it to a printer or other output device.
    -Mark

  4. #4
    5 Star Lounger st3333ve's Avatar
    Join Date
    May 2003
    Location
    Los Angeles, California, USA
    Posts
    705
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Resuming a batch file after application closes (XPPro SP2)

    I'm not sure exactly what Mark was contemplating when he referred to "returning information to the script," so I'm probably missing something, but one simple-minded answer to your question would be to use the START command with the /W switch to execute Word. The /W switch causes the batch file to start the specified application and wait for it to end before moving to the next line in the batch file.

    You can find documentation of START and the other "DOS" commands (as we geezers call them) in the Help & Support Center on your PC.

    UPDATE: I should have mentioned one possible "gotcha" with START: If you need to enclose the program you're starting in quotes (e.g., because the path to it contains spaces), START may think the quoted string is the Title parameter, rather than the program to be started. To avoid this glitch, you just need to add a dummy "title" parameter before the program parameter. Here's a sample batch file line that starts Word 2002 with the /n switch (i.e., in this sample, the /W switch applies to START and the /n switch applies to Word) and adds a dummy title parameter:
    <pre>START /W "dummy title" "C:Program FilesMicrosoft OfficeOffice10WINWORD.EXE" /n</pre>


  5. #5
    Plutonium Lounger
    Join Date
    Oct 2001
    Location
    Lexington, Kentucky, USA
    Posts
    12,107
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Resuming a batch file after application closes

    It would really be worth your while to check out AutoIt v3 - Automate and Script Windows Tasks. Take a look at Alan Miller's <post:=602,668>post 602,668</post:> for a most recent example of its use. If you can "deal with" the batch language, you'll do OK with AutoIt too.

  6. #6
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Hatsukaichi, Hiroshima, Japan
    Posts
    904
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Resuming a batch file after application closes

    Thanks, for what I was trying to do START /w worked just fine.

    Best wishes,

    Chris

Posting Permissions

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