Announcement

Collapse
No announcement yet.

Strange behavior using SHELL

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Strange behavior using SHELL

    For many years I used the SHELL command, but what happened to me today has something strange, at least for me.
    From a program (# 1) I call another program (# 2) with the Shell command. The # 2 program, in turn calls one at a time up to three other programs, again with the SHELL command. I return to the # 1 program at this point. And it is here that the problems begin: when I try to get out of the # 1 program, it will not close and I have to try three or four times, before exiting. Maybe you can not nest multiple SHELL functions? How to solve?
    I tried with:
    - SHELL "CMD / C MyProgram.exe"
    - Pid ??? SHELL = (MyProgram.exe, 1)
    - Pid ??? SHELL = (ENVIRON $ ("COMSPEC") & "MyProgram.exe, 1)
    mailto:[email protected]
    From Italy.

  • #2
    The Shell command runs synchronously. The calling application is suspended until the Shelled application terminates.
    If you want to terminate the calling application when any of the other Shelled applications are still running, you need to use the Shell FUNCTION which is asynchronous..

    i.e instead of "SHELL "CMD /C:\MyProgram.exe", use
    lngReturn = "SHELL("CMD /C:\MyProgram.exe")

    Comment


    • #3
      There's no limit on "nesting" shells.

      It sounds to me like one of your shelled programs is not exiting after it SHELLs to the next program, and is thereby holding up the whole chain.

      Corrected; Thanks Stuart...

      To amplify what Stuart said, if you use the SHELL function...

      x = SHELL("whatever")

      ...it is asynchronous, meaning that your program continues to run at the same time as the shelled program.

      If you use the SHELL statement...

      SHELL "whatever"

      ...then your main program will wait for the shelled program to exit before it executes the next line of code.

      If you are running your program in a console window you can end up with more than one program "inside" the console at the same time. They will all need to close before the console windows closes.
      "Not my circus, not my monkeys."

      Comment


      • #4
        Eric, you've explained it bass-ackward

        The function is asynchronous and will not wait. The statement is synchronous and will wait,

        (There would be no point in the function returning the Process ID if it did not continue until the Process terminated)

        Comment


        • #5
          Sigh. thanks Stuart.
          "Not my circus, not my monkeys."

          Comment


          • #6
            You can replace the SHELL statement except you get to decide when it returns: when the process ends or when the process has completed initializing (GUI programs; it's a little trickier to do this with console programs) (but doable with a cooperating program):

            Win 32: Monitor Process with ShellExecuteEx June 22, 2001

            Michael Mattias
            Tal Systems (retired)
            Port Washington WI USA
            [email protected]
            http://www.talsystems.com

            Comment

            Working...
            X