Announcement

Collapse
No announcement yet.

Shelled Application's Current Directory

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

  • Shelled Application's Current Directory

    With apps I've written I don't recall having to think about this before ...

    From what I read and from my testing, a program opened by SHELL uses the calling program's folder as its current folder.

    If I don't want that I can use ChDir, such as "ChDir Exe.Path$" to change the current directory of the called app - either before calling the app or from within the called app.

  • #2
    Correct. You can also use ShellExecute directly rather than PB's Shell and set the lpDirectory parameter if you want to open your application in another location (Like many BASIC functions, SHELL is a simplified wrapper to the API function)

    HINSTANCE ShellExecuteA(
    [in, optional] HWND hwnd,
    [in, optional] LPCSTR lpOperation,
    [in] LPCSTR lpFile,
    [in, optional] LPCSTR lpParameters,
    [in, optional] LPCSTR lpDirectory,
    [in] INT nShowCmd
    );​

    [in, optional] lpDirectory

    Type: LPCTSTR

    A pointer to a null-terminated string that specifies the default (working) directory for the action. If this value is NULL, the current working directory is used. If a relative path is provided at lpFile, do not use a relative path for lpDirectory.​

    Comment


    • #3
      Yes and yes.
      Code:
      FUNCTION PBMAIN  'c:\junk1\caller.bas
       SHELL "\junk2\called.exe"
      END FUNCTION  
      
      FUNCTION PBMAIN  'c:\junk2\called.bas
       ? CURDIR$,,EXE.FULL$ 'c:\junk1
      END FUNCTION


      Some other methods and shelling to a batch file https://forum.powerbasic.com/forum/u...lem-with-shell

      Comment


      • #4
        You can also use ShellExecute directly rather than PB's Shell
        Both CreateProcess() and ShellExecuteEx() also allow specification of the directory for the subordinate process.
        Michael Mattias
        Tal Systems (retired)
        Port Washington WI USA
        [email protected]
        http://www.talsystems.com

        Comment

        Working...
        X