Community
    • Login

    Python : Accessing variables set via NppExec env_set

    Scheduled Pinned Locked Moved General Discussion
    4 Posts 3 Posters 587 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Anthony BlincoA
      Anthony Blinco
      last edited by

      Is it possible to access environment variables set by the NppExec env_set command?
      So my env_set command looks like this (Which is executed at startup);
      env_set PROJECT=C:\MyProjects\Project1

      I am using os.getenv(“PROJECT”) but it isn’t returning a value. When i use os.getenv(“PATH”) i get a value.

      Is there a way to retrieve NppExec environment values or should i go about this another way?

      Thanks for any help.

      Michael VincentM Alan KilbornA 2 Replies Last reply Reply Quote 0
      • Michael VincentM
        Michael Vincent @Anthony Blinco
        last edited by

        @Anthony-Blinco said in Python : Accessing variables set via NppExec env_set:

        Is there a way to retrieve NppExec environment values or should i go about this another way?

        NppExec variables I don’t think so. Using NppExec to set system environment variables - I don’t think so either. Running Notepad++ inherits the default environment. If you open a Command Prompt or Powershell prompt, set a special environment variable (myvar) and then open Notepad++ from that command line, you’ll see myvar in NppExec:

        ce76d210-52ae-41b2-96c9-7e60fdf4cdad-image.png
        78863d16-b663-4539-bfdd-5fd98f165537-image.png

        However, that’s because NppExec is deriving its environment from Notepad++. If you then set environment variables in NppExec, they won’t be reflected back in that original Command Prompt you launched Notepad++ from. Nor will PythonScript - which is deriving its environment from Notepad++ - see any NppExec set environment variables. Maybe this screenshot from Process Explorer helps explain:

        cdaa5d1a-321d-4bdb-8669-5697b1bd4db2-image.png

        The cmd.exe under Notepad++ is me launching a CMD.exe process in NppExec console to have it “show up” in Process Explorer. You can see the hierarchy. Environment variable inheritance flows down, not up.

        Note, this is my “diagnosis” - this may not be fact, but is backed by my experimentation. Anyone who knows for sure feel free to correct me.

        Cheers.

        1 Reply Last reply Reply Quote 2
        • Alan KilbornA
          Alan Kilborn @Anthony Blinco
          last edited by

          @Anthony-Blinco said in Python : Accessing variables set via NppExec env_set:

          or should i go about this another way?

          Not sure at all what your end goal is, but to keep it simple you could probably “communicate” via files; you know NppExec writes to a file (presume it can do this?) and PythonScript looks for the file and reads it.

          There are more communication methods possible with Python if you need something “more complicated” but NppExec might be a limiting factor in what it can do (really no idea on that front as I’m not a NppExec user).

          1 Reply Last reply Reply Quote 3
          • Anthony BlincoA
            Anthony Blinco
            last edited by

            Ok thanks much. I appreciae it
            I’ll use files to communicate

            1 Reply Last reply Reply Quote 1
            • First post
              Last post
            The Community of users of the Notepad++ text editor.
            Powered by NodeBB | Contributors