Skip to content

Commit

Permalink
Add echo of piped stdin to stdout.
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonherzog committed Apr 18, 2017
1 parent 38f63ab commit 20196f2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ Prevent system sleep and keep display on:
```dos
nosleep --display
```

Echo stdin from a pipe to stdout and prevent sleep until the pipe is terminated:
```dos
ping -n 10000 127.0.0.1 | nosleep
```

*Note that user initiated power events will not be affected.*

License
Expand All @@ -36,3 +42,4 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

19 changes: 13 additions & 6 deletions nosleep/nosleep.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@
#define _CRT_NONSTDC_NO_WARNINGS
#include <Windows.h>


#include <conio.h>
#include <io.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

static const char VERSION[] = "1.0";
static const char VERSION[] = "1.1";
static const char AUTHOR[] = "Brandon Herzog";

static bool display_required;
Expand All @@ -54,7 +54,7 @@ static void help()
" --display keep display active\n"
" --version show version\n"
" --help show help\n"
"", stdout);
"", stdout);
exit(EXIT_SUCCESS);
}

Expand Down Expand Up @@ -100,9 +100,16 @@ int main(int argc, char **argv)
exit(EXIT_FAILURE);
}

fputs("Wide awake. Press any key to exit...\n", stdout);
fflush(stdout);
getch();
if (isatty(fileno(stdin))) {
fputs("Wide awake. Press any key to exit...\n", stdout);
fflush(stdout);
getch();
} else {
int ch;
while ((ch = fgetc(stdin)) != EOF) {
fputc(ch, stdout);
}
}

exit(EXIT_SUCCESS);
}

0 comments on commit 20196f2

Please sign in to comment.