Announcement

Collapse
No announcement yet.

I'm having a problem with SHELL

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

  • #21
    Dale, thanks again for your help.


    Of course you don't get the exit return. Doing that would require the SHELL statement, and your program would be blocked till it finished.
    I don't get a return code because the 3rd party closes itself and the small CC program that shelled to it, Ithink. At this stage I'm not sure.

    Mike, MM and yourself may well be correct. Thanks for the link.

    Comment


    • #22
      Okay, one more time. If you use SHELL function, it does not matter what 3rd party program does, the PBCC program will not get a return value.
      Dale

      Comment


      • #23
        That is one of the reasons I used CreateProcess
        CMD shortcut to open any location:
        %windir%\system32\cmd.exe /k " cd\ & x: & cd x:\xxxx
        Change to run as administrator
        How long is an idea? Write it down.

        Comment


        • #24
          This will maximize a PBWIN program but couldn't get to work with a PBCC program.
          If it can be done, Eric Pearson and selected others would know how to do this.

          Milliseconds = %INFINITE
          sProgram = "c:\sql\bin\dotysql.exe"
          result = WaitShell(sProgram, %SW_SHOWMAXIMIZED, Milliseconds,ExitCode) 'result 1=success
          CMD shortcut to open any location:
          %windir%\system32\cmd.exe /k " cd\ & x: & cd x:\xxxx
          Change to run as administrator
          How long is an idea? Write it down.

          Comment


          • #25
            Dale, no need to have a conniption, as I showed in #5, I'm using the SHELL statement.

            Comment


            • #26
              Doh!

              As Dale pointed out, I jumped to a code example that was incorrect. I'll delete it in a moment.

              I was recalling that there IS a way to obtain such a code, and it seems Mike has identified it as CreateProcess.

              Next time, I'll go back to my actual source code rather than rely on memory (what's left of it...)

              -John

              Comment


              • #27
                Originally posted by Dale Yarker View Post
                Okay, one more time. If you use SHELL function, it does not matter what 3rd party program does, the PBCC program will not get a return value.
                Nothing to say you can't go out and get it though. Of course, if you're gonna run through three stages of (s)hell then everybody needs to cooperate to bubble the value of interest back
                Code:
                '
                ' Returns 0xffffffff on error
                ' A return of %STILL_ACTIVE means the process is still running
                '
                FUNCTION GetExitCodeProcessId(BYVAL processId AS DWORD, BYVAL waitForExit AS LONG) AS DWORD
                
                  LOCAL hProcess AS DWORD
                  LOCAL exitCode AS DWORD
                
                  hProcess = OpenProcess(%PROCESS_QUERY_INFORMATION Or %SYNCHRONIZE, 0, processId)
                  IF hProcess = 0 THEN
                    FUNCTION = &H0FFFFFFFF
                    EXIT FUNCTION
                  END IF
                
                  IF waitForExit >< 0 THEN
                    WaitForSingleObject(hProcess, %INFINITE)
                  END IF
                
                  GetExitCodeProcess(hProcess, exitCode)
                  CloseHandle(hProcess)
                
                  FUNCTION = exitCode
                
                END FUNCTION

                Comment


                • #28
                  I wonder why I have no problems getting SHELL to work.
                  Code:
                  caller.bas
                  
                  ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
                  
                  FUNCTION PBmain as LONG
                  
                      LOCAL exitval as DWORD
                  
                      StdOut "Shell to external app"
                  
                      SHELL "called.exe",4, EXIT TO exitval
                  
                      Stdout "Returned from external app and the exit code = "+format$(exitval)
                  
                      waitkey$
                  
                  End FUNCTION
                  
                  ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
                  
                  called.bas
                  
                  ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
                  
                  FUNCTION PBmain as LONG
                  
                      StdOut "Hi, I am the called application"
                  
                      FUNCTION = 1234
                  
                  End FUNCTION
                  
                  ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
                  
                  Result
                  
                  Shell to external app
                  Hi, I am the called application
                  Returned from external app and the exit code = 1234
                  hutch at movsd dot com
                  The MASM Forum

                  www.masm32.com

                  Comment


                  • #29
                    The shelled to program may only work correctly if in the current directory.
                    CMD shortcut to open any location:
                    %windir%\system32\cmd.exe /k " cd\ & x: & cd x:\xxxx
                    Change to run as administrator
                    How long is an idea? Write it down.

                    Comment


                    • #30
                      Using a path is normal when using SHELL. In the above test pieces the called file is in the same directory. SHELL works on any accessible file on the computer.
                      hutch at movsd dot com
                      The MASM Forum

                      www.masm32.com

                      Comment


                      • #31
                        The shelled to program will start, but it may attempt to access files in the current directory instead of its own folder.
                        Also, if shelling to a batch file the other commands in the batch file may not execute.unless the batch file changes directory to its own directory.
                        It is like using a shortcut, but not setting the working folder or Start in folder.
                        I think he also wanted a return code and to open another window which would mean shelling using the environment.
                        CMD shortcut to open any location:
                        %windir%\system32\cmd.exe /k " cd\ & x: & cd x:\xxxx
                        Change to run as administrator
                        How long is an idea? Write it down.

                        Comment


                        • #32
                          Originally posted by Mike Doty View Post
                          Also, if shelling to a batch file the other commands in the batch file may not execute.unless the batch file changes directory to its own directory.
                          Absolutely. Definitely a trap. Spent many happy(?) hours discovering and resolving this!

                          [I]I made a coding error once - but fortunately I fixed it before anyone noticed[/I]
                          Kerry Farmer

                          Comment


                          • #33
                            This is not a problem with SHELL, its a problem of code design.
                            Code:
                            CHDIR "your-path"
                            SHELL "yourfile.exe",4, ------
                            hutch at movsd dot com
                            The MASM Forum

                            www.masm32.com

                            Comment


                            • #34
                              Thanks all for the input, I would have "liked" it all but the board won't let me.

                              Comment


                              • #35
                                Okay, one more time. If you use SHELL function, it does not matter what 3rd party program does, the PBCC program will not get a return value
                                Ok, once only because that is all that should be required:

                                Sure it will. Of course, the immediate return from the execution of the PB SHELL function is the process ID, not the return code of the launched program.

                                .... BUT...

                                You can always use that process ID to get a handle to that process with the WinAPI "OpenProcess()" function, then use that handle to get the exit code of that launched process with the deviously-named "GetExitCodeProcess()" WinAPI function.

                                Part of the issue in this thread appears to be semantic, in that the return code from a PB statement, the exit code of a launched process and the system variable ERRORLEVEL used by the the third-party program CMD.EXE are being tossed around as though they are interchangeable. News Flash: They Ain't Interchangeable.

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

                                Comment

                                Working...
                                X