Community
    • Login

    NppExec compiling multiple languages

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    nppexec
    4 Posts 2 Posters 2.4k 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.
    • Pietro NobiliP
      Pietro Nobili
      last edited by

      Hey there! I write mainly in cpp, java and python, so I made various script to compile/run/interpret my files. On their own they work as expected but I’m running out of hotkeys, so I wanted to wrap them all in only two scripts, calling the right commands by reading the extension of the file, like this:
      if $(EXT_PART) == ".py" (
      py $(FILE_NAME)
      ) else (
      echo unrecognized extension
      )
      When run this, a bracket is printed ) and then I get the following error
      ; starting child process: ")"
      CreateProcess() failed with error code 2:
      The system cannot find the file specified.

      On its own py $(FILE_NAME) works nicely, so the problem shouldn’t be there.
      Thanks

      Claudia FrankC 1 Reply Last reply Reply Quote 0
      • Claudia FrankC
        Claudia Frank @Pietro Nobili
        last edited by

        @Pietro-Nobili

        the error itself points to the closing round bracket not being a program which can be executed.
        My knowledge may be a little be outdated about the latest features of nppexec but from what
        I remember the if syntax is

        if condition goto label
        

        Checkout the doc and manual which comes with the plugin.

        Cheers
        Claudia

        1 Reply Last reply Reply Quote 1
        • Pietro NobiliP
          Pietro Nobili
          last edited by

          Prompted by your observation I did some tests and, as far as I can tell, NppExec’s console only runs the last line of a command, hence the unrecognized bracket.
          A script launched after pressing F6 does execute all the lines but only one after the other, so any kind of multiline command doesn’t work.
          I solved the problem with a somewhat artless bodge, calling launch.bat $(NAME_PART) $(EXT_PART) from my script, that runs this external script, saved somewhere reached by the environmental variables:

          @ECHO OFF
          SETLOCAL
          SET filename=%1
          SET extension=%2
          
          if %extension%==.py goto :python
          if %extension%==.cpp goto :cpp
          if %extension%==.java goto :java
          goto :error
          
          :python
          py %filename%%extension%
          goto :end
          
          :cpp
          %filename%.exe
          goto :end
          
          :java
          java %filename%
          goto :end
          
          :error
          echo Unrecognized extension
          
          :end
          ENDLOCAL
          

          And this is compile.bat if anyone is interested, called with the same arguments:

          @ECHO OFF
          SETLOCAL
          SET filename=%1
          SET extension=%2
          
          if %extension%==.py goto :python
          if %extension%==.cpp goto :cpp
          if %extension%==.java goto :java
          goto :error
          
          :python
          echo Python is interpreted
          goto :end
          
          :cpp
          g++ -o %filename% %filename%%extension%
          goto :end
          
          :java
          javac %filename%%extension%
          goto :end
          
          :error
          echo Unrecognized extension
          
          :end
          ENDLOCAL
          

          Thanks, Pietro

          Claudia FrankC 1 Reply Last reply Reply Quote 0
          • Claudia FrankC
            Claudia Frank @Pietro Nobili
            last edited by Claudia Frank

            @Pietro-Nobili

            Pietro, I had something different in mind.
            Copy the following into nppexec dialog and run it on a python script,
            then you should see the full file path output, when running on txt file
            only a statement is shown. No need for an addition batch file.

            if $(EXT_PART) == .py goto python
            if $(EXT_PART) == .txt goto whatever
            goto end
            
            :python
            echo run full file path:$(FULL_CURRENT_PATH)
            goto end
            
            :whatever
            echo some text file
            
            :end
            echo "END"
            
            1 Reply Last reply Reply Quote 1
            • First post
              Last post
            The Community of users of the Notepad++ text editor.
            Powered by NodeBB | Contributors