Community

    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    nppexec - sleep command causes printf output to cease

    Help wanted · · · – – – · · ·
    3
    4
    213
    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.
    • Bryan Taylor
      Bryan Taylor last edited by

      Hi everyone.
      I have notepad++ setup for c program writing/compiling/execution using nppexec plugin. Everything seems to work fine, unless I call a sleep command in a script, and then any ‘printf’ output ceases because the sleep command stops console output before the printf statements are actually executed and printed in the console output. It there a setting I missed or should I be calling something other than ‘sleep’ to put the program to sleep for a while?? I could probably use a function to cause a ‘sleep’ period, but with sleep already there, why should I? Just curious if anyone has the same problem or if there a setting or workaround besides using custom function. The compiled program still works if run from a cmd window, and it is actually running in the nppexec background of the console, just no console output. Here is some sample code if anyone cares to test their setup. Try it with or without the sleep command to see if the problem can be reproduced. Thanks in advance!

      #include <stdio.h> 
      #include <time.h>
      //#include <math.h>
      //#include <unistd.h>
      
      int funca (void);
      int funcb (void);
      int funcc (void);
      
      int main () {
      int x = funca();
      sleep(5);
      return x;
      }
      
      int funca(void){
      	printf("function a start\n");
      	int x = funcb();
      	printf("back from b\n");
      	funcc();
      	printf("back from c\n");
      	return 1;
      }
      
      int funcb(void){
      	printf("inside func b\n");
      	return 1;
      }
      
      int funcc(void){
      	printf("inside func c\n");
      	return 1;
      }
      

      Just wondering if this is an issue with notepad++, nppexec, or my setup.

      dinkumoil 1 Reply Last reply Reply Quote 1
      • dinkumoil
        dinkumoil @Bryan Taylor last edited by dinkumoil

        @Bryan-Taylor

        The NppExec manual states the following in chapter 4.5. Console output redirection:

        NppExec uses pipes to redirect child process’es output to NppExec’s Console window and to redirect user’s input from NppExec’s Console window to child process’es input. Such approach has several known limitations:

        • no output may be shown until child process ends (if this child process performs a lot of operations without explicit flushing of its output);

        Thus, you should take care that a fflush(stdout); is been executed after every printf command. Ideally you could wrap printf into an own function that additionally calls fflush.

        I’m a user of NppExec as well and also have set it up for compiling and executing the current file’s code, even for various programming languages. But I don’t use the console redirection feature of NppExec to avoid such problems like yours.

        If you are interested in my NppExec script that turns Notepad++ into some kind of rudimentary IDE have a look at my GitHub ScriptCollection repo.

        Bryan Taylor Lowell Justice 2 Replies Last reply Reply Quote 4
        • Bryan Taylor
          Bryan Taylor @dinkumoil last edited by

          @dinkumoil Thanks for that. Spot on. I may toy with the custom function because at deployment I usually just comment out all the printf commands anyway --I really need to move more into using debugger tools rather than inserting printf commands to watch whats going on…but 30 years of bad habits are 30 years of bad habits! Lol. But I did look at your script and it looks like it just launches a cmd window to run the program and has a pause command to keep it open until the user has a chance to look at it, is that right? (Along with similar code for many other languages too.) Anyhow, thanks again!!
          Cheers

          1 Reply Last reply Reply Quote 0
          • Lowell Justice
            Lowell Justice @dinkumoil last edited by

            @dinkumoil how could I make a script like this for c++?

            1 Reply Last reply Reply Quote 0
            • First post
              Last post
            Copyright © 2014 NodeBB Forums | Contributors