1

Does anyone know how to get the output of an batch-file on NPPExec and input it to a filename?

For example:

cmd /c "$(NPP_DIRECTORY)\datetime.bat"
set DATI = $(OUTPUT)
cmd /c copy "$(FULL_CURRENT_PATH)" "D:\Notepad++ - Backups\$(FILE_NAME).$(DATI)" /Y

But my example doesn't work on my personal tests... so please some help?

303
  • 2,417
  • 1
  • 11
  • 25
John_Magdy
  • 23
  • 8
  • I would do it the other way: call datetime.bat with param $(FULL_CURRENT_PATH) and do the copy inside the batch file. To answer your question: This works for me: `cmd /c echo %DATE% set DATI = $(OUTPUT) echo "Output from cmd is" $(DATI)` – Lars Fischer Jun 15 '17 at 12:05
  • doesn't work :( please some help ? – John_Magdy Jun 15 '17 at 12:17
  • always return this message on the console > CreateProcess() failed with > error code 2: > The system cannot find the file specified. > 1 file(s) copied. – John_Magdy Jun 15 '17 at 12:39
  • @elzooilogico code posted is a NPP_EXEC script. NPP_EXEC supports things like `$(FULL_CURRENT_PATH)` and `$(OUTPUT)`. The Errror Message `CreateProcess failed()` sounds like some problem with some prorgram. Either a path Problem or an access rights problem. @John_Magdy: I would recommend to debug the `datetime.bat` outside of NPP_EXEC on its own inside a cmd. Take care of used PATH and other environment settings. Then comment lines to see which line causes the error message. – Lars Fischer Jun 15 '17 at 13:24
  • @John_Magdy `CreateProcess() failed with > error code 2: > The system cannot find the file specified.` : Are you sure that `datetime.bat` is stored in the directory `$(NPP_DIRECTORY)` ? – Lars Fischer Jun 15 '17 at 13:27
  • yes its stored with the original Notepad++'s installion folder - can't understand what do you mean with your first Comment (after debugging it how to get the output it if its exceuted out of NPPExec ??) – John_Magdy Jun 15 '17 at 14:11
  • @John_Magdy : 1. Open a cmd. 2. cd into the directory of $(NPP_DIRECTORY), 3. execute datetime.bat, 4. see if it works on a cmd or if the batch file on itself gives some error. If you are 100 percent sure that the batch file for itself works fine: advance to the next step and comment out all lines in your NPP_EXEC script but the very first line. Then see if that line on itself works as expected. If yes uncomment the next line and see if both lines work together. And so on... – Lars Fischer Jun 15 '17 at 14:19
  • 1- on Command prompt it works 100% without any errors but when i tried to excute the batch file on itself it excuted and then closed after less than 1 second 2- the example code which i had listed on my original post it almost works 70% it echo the output of the batch file on the NPPExec's Console and saves the file on my 'D:\....Backup' directory but without the .DATI's Value (Batch file's output) so i need help on last line as i understand – John_Magdy Jun 15 '17 at 15:20
  • What happens when you replace the last line of your NPP_EXEC script with `echo "Output from cmd is" $(DATI)` ? If it writes the date, then your copy command has a problem. If the `echo ... ` does not print the date, then the problem is in the line with the `set` or with the value of `$(OUTPUT)`. The documentation mentions the command `npe_console v+` that you might want to insert as the very first command of your script. Also take care that the line with the datetime.bat and the line where `$(OUTPUT)` is used, are directly behind each other. – Lars Fischer Jun 15 '17 at 15:49
  • http://i.imgur.com/PNAmWSQ.png - doesn't show the value of $(OUTPUT) ($(DATI)) - it gives me The syntax of the command is incorrect. when i use npe_console v+ – John_Magdy Jun 15 '17 at 16:07
  • I have no experience with `nppexec` but in pure batch-file scripting you should avoid using spaces around the equal sign when you use the `set` command to give a variable a value. Otherwise, the name of the variable will contain a space as well. – 303 Jun 15 '17 at 19:51
  • proplem not resolved yet :( – John_Magdy Jun 15 '17 at 22:56
  • @John_Magdy `npe_console v+` was added in npp_exec version 0.3.1 in June 2009 (at least the documentation hints at that date). What is your version of npp_exec? By the way, I would really recommend to do everything inside a batch script and pass the fullpath as argument to it. Scripting in cmd or powershell is well understood and documented. You will find many tutoriala. Advanded Scripting (like capturing the output) in `npp_exec` requires much more experimentation and rtfm. – Lars Fischer Jun 15 '17 at 22:59
  • my installed NPPexec v0.5.3 - Feb 2015 * but anyway iam really getting crazy becuase of this proplems.... and i will try doing my small project on CMD or powershell as you have said. – John_Magdy Jun 16 '17 at 12:32

0 Answers0