Re: Problem when executing application from batch file



On Tue, 4 Oct 2005 18:01:22 -0400, "Jack" <replyto@newsgroup> wrote:

>Hello,
> I have that strange problem. My application can accept commands
>from command prompt and if there are more commands it will store commands in
>buffer and execute one by one
>Everything is fine and dandy when application is up and running and after
>that the comands (multi-commands from batch file) are sent.
>However, when application is not running and the batch file is used with
>multi-commands, then the first command will invoke the application and the
>batch execution will stop (pause). When application is closed then
>automatically, the second batch line will invoke the application again.
>That strange behaviour will be repeated until all commands will be sent from
>batch file.

Having followed this thread, I think I've a fair idea of what you want
to do.

It is news to me that the default behaviour of a Batch file is to wait
until the /Windows/ App is closed
- and that does not happen on my Win95 setup (just checked)

But it does happen on my XP Pro setup - amazing !

If you write a tiny stripped down loader for your App and use:
MiniLoader /365544776

Then MiniLoader can launch your real App with the Commandline as
usual, it can wait until your app is responding, then terminate to
allow the next line of the batch file to be executed.

Next time MiniLoader runs, it will find your real App is already
running so it can pass on the info and terminate immediately

Making your real App into an AX EXE would make things much simpler for
you.

Also I would not rely too much on App.PrevInstance, use a Mutex
instead - that can be used by both your App and MiniLoader.exe

Also, if you use RegisterWindowMessage you can get a guaranteed unique
message ID that can be used with WM_BROADCAST to identify an already
running App - if any

The simplest method is to use an AX EXE, just make its exposed Class
MultiUse (default) and keep it alive by giving it a Form

Another method would be to load the real App directly from the batch
file, but give it an extra parameter /b[atch] which makes it launch a
clone of itself, pass on the Command line ( excluding /b ) and then
terminate to allow the batch file to continue

That might be the most 'granular' method, as you just land up with one
EXE, and loading 'clones' will be trivial as your check for /b or
another instance will take place in Sub Main()

On balance I would go for the last option.

BTW I would be interested to hear how you are identifying the existing
instance and passing on the Command line
- I have that wrapped in a Delphi DLL using RegisterWindowMessage and
WM_COPYDATA

HTH




.



Relevant Pages

  • Re: Application starts too soon
    ... expecting a network connection to exist. ... > The application runs froma a batch file. ... Finally the command prompt arrives, ... > think the app tries to run, encounters an error, and exits. ...
    (microsoft.public.windowsxp.embedded)
  • Re: Application starts too soon
    ... Windows XPE site and looked thru the two XPE books and found nothing on this ... >> The application runs froma a batch file. ... >> The batch file has my exe followed by a Shutdown command ... >> think the app tries to run, encounters an error, and exits. ...
    (microsoft.public.windowsxp.embedded)
  • 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: SEPKILL /im SMC.EXE /f
    ... Subject: SEPKILL /im SMC.EXE /f ... Save the following as a batch file and execute it ... If done from a batch file the command is completed only when the process is stopped. ...
    (Bugtraq)