Subscribe

Run the file only if compiled successfully?

  1. 2010-11-18 22:51:43 PST
    Hi guys. First of all, thanks a lot for NppExec, it really saves time! I've made a command for NppExec that compiles and runs C or Java source code. The problem is, if there was already an output file in the folder (.exe for C or .class for Java) it would still run that file, even if it did not compile successfully at this time. I thought I would delete the existing output file before compiling, but is that possible? Another issue is that for some reason .exe files from C source code do not run correctly in NppExec console. They do run perfectly in windows cmd though. However, .class files from Java source code do run well in NppExec console. Thanks in advance. :)
  2. 2010-11-19 00:44:20 PST
    There are several questions, so here are several answers: 1) Run the .exe file only in case of successful compilation, example for GCC: cmd /c $(g++) -c "$(FULL_CURRENT_PATH)" -o "$(obj).o" && $(g++) "$(obj).o" -o "$(obj).exe" && "$(obj).exe" Explanation: all the commands above are executed by the command interpretter cmd.exe which can be seen from "cmd /c" at the beginning. The special "keyword" or "operator" && tells cmd.exe the following: execute the command next to && only in case of successful execution of the previous command. I.e. the logic of this command line is the following: IF $(g++) -c "$(FULL_CURRENT_PATH)" -o "$(obj).o" THEN // compiled OK - building the .exe IF $(g++) "$(obj).o" -o "$(obj).exe" THEN // built OK - running the .exe "$(obj).exe" ENDIF ENDIF Some additional information can be found in the NppExec Manual under the section 4.4. 2) Delete the file. And again we use cmd.exe: cmd /c del "$(obj).exe" Some additional information can be found in the NppExec Manual under the section 4.4. 3) Run the console program in its own console window. Described in the NppExec Manual under the section 3.3.
  3. 2010-11-19 03:32:14 PST
    Thanks a lot! :) 1) I should have read the manual, it's right there in section 4.4. =\ I am currently using Tiny C Compliler for C and JDK for Java.. But if GCC can compile both of them.. Do I get it from http://gcc.gnu.org/install/binaries.html ? MinGW version does not seem to include java compiler.. and Cygwin is somewhat compilcated to download. 2) I won't need to delete the files in this case. 3) Yeah, I came up with the same solution.
  4. 2010-11-19 05:18:35 PST
    Personally I use TCC to compile small apps/tools because TCC is tiny, fast and produces small executables. However, I am not sure about its optimization (if any), so I prefer GCC for more serious projects. Oh, when I say "GCC", I actually mean "MinGW" :) Finally, when I have a complicated project, I prefer Visual C++ Express because of its powerful and handy debugger. As for optimization, IMHO it is equal to GCC/G++ though G++ produces larger executables than cl.exe.
  5. 2010-12-03 07:01:57 PST
    Hi again.. :) I decided to use TCC to compile C and JDK for Java, because I don't have any big projects with C yet and MinGW version of GCC does not seem to compile Java. So I think I will omit GCC for now. With the help of manual I managed to make my C and Java files run in NppExec's console by these scripts: "$(NPP_DIRECTORY)\tcc\tcc.exe" "$(FULL_CURRENT_PATH)" -run cmd /c cd "$(CURRENT_DIRECTORY)" && javac "$(FILE_NAME)" && java "$(NAME_PART)" It would be fine if all C files ran correctly in NppExec's console, which is not the case. So I'd like to make both C and Java compiled files to compile (or display debugging information) in NppExec's console, but to run (only on successful compilation) in their own console windows. Yeah, Java is is running fine in NppExec's console, but.. I just want the "compile and run" processes for C and Java to work in the same manner. :) The scripts I made up to do make it work this way (but it does not care if it compiled successfully) are as follows (for C and Java respectively): "$(NPP_DIRECTORY)\tcc\tcc.exe" "$(FULL_CURRENT_PATH)" -o "$(CURRENT_DIRECTORY)"\$(NAME_PART).exe NPP_RUN cmd /k ""$(CURRENT_DIRECTORY)"\$(NAME_PART).exe" cd "$(CURRENT_DIRECTORY)" javac "$(FILE_NAME)" NPP_RUN cmd /k "java $(NAME_PART)" Tried something like.. cmd /c "$(NPP_DIRECTORY)\tcc\tcc.exe" "$(FULL_CURRENT_PATH)" -o "$(CURRENT_DIRECTORY)"\$(NAME_PART).exe && NPP_RUN cmd /k ""$(CURRENT_DIRECTORY)"\$(NAME_PART).exe" But it won't work. I think because it's TCC does not understant '&&' operator.. And for Java: cmd /c cd "$(CURRENT_DIRECTORY)" && javac "$(FILE_NAME)" && NPP_RUN cmd /k "java $(NAME_PART)" But it obviously says "'NPP_RUN' is not recognized as an internal or external command, operable program or batch file.", since it is sent to cmd, not to NppExec's console.. So I wonder if this idea can be implemented using TCC and JDK.. I mean compiling in NppExec's console and running in a new window on successful compilation.
  6. 2010-12-04 09:12:45 PST
    NPP_RUN is internal command of NppExec, so it indeed can't work from within systems's cmd. The only solution I see is to delete the previous .exe file (if any) before compiling the sources. In such situation, in case of compilation failed, you'll get a message "File not found" when trying to execute the .exe or the java's compiled file.
  7. 2010-12-04 09:58:11 PST
    Yep, tried that too. :) It deletes the file, tries to compile the code, if there is a problem it displays debugging information, AND (since I am not using && operator, which does not work for NPP_RUN) it runs cmd window to display 'file not found', since it was not compiled. Все равно спасибо и на этом.)
  8. 2011-10-14 05:40:19 PDT
    To start seperate window from cmd.exe, you can use 'start' command. I'm using following scripts to run a program in externel console only when compilation was successful. cmd /c ""$(gcc_path)" -o "$(NAME_PART)" "$(FULL_CURRENT_PATH)" && start cmd /c ""$(CURRENT_DIRECTORY)\$(NAME_PART).exe" & pause"" and for Java: cmd /c ""$(javac_path)" "$(FULL_CURRENT_PATH)" && start cmd /c ""java.exe" -classpath "$(CURRENT_DIRECTORY)" "$(NAME_PART)" & pause""
  9. 2011-10-14 06:06:53 PDT
    Thanks, that works. :) I changed it a bit to work with TCC and jump to a new line in cmd window before Press any key to continue... cmd /c ""$(NPP_DIRECTORY)\tcc\tcc.exe" "$(FULL_CURRENT_PATH)" -o "$(CURRENT_DIRECTORY)"\$(NAME_PART).exe && start cmd /c ""$(CURRENT_DIRECTORY)"\$(NAME_PART).exe & echo. & pause"" As of Java and C++, they seem to run fine in NppExec console, so I prefer to run them there, rather than in a new window. :)
Jump To:
< Previous | 1 | Next >

Add a Reply

This forum does not allow anonymous participation.

Log in to add a reply. Not registered? Create an account to participate and receive email updates when replies are posted to this topic.