Skip to content

z9u2k/misc-utils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Misc Utils

A repo for random utilities.

Building

$ make all

What's in here?

STDIO redirection to pipes

It is sometimes usedful to be able to redirect stdin and stdout to processes instead of files, without forking a process.

While this can be achieved with Bash process substitution:

#!/bin/bash
STDOUT_PIPE_CMD="logger -p daemon.info"
STDERR_PIPE_CMD="logger -p daemon.err"
PROC_EXE="some_service"
PROC_PARAMS="-p --param2 param2_value"

exec $PROC_EXE $PROC_PARAMS 1> >($STDOUT_PIPE_CMD) 2> >($STDERR_PIPE_CMD)

This is a non-standard extension and isn't always available (e.g. on FreeBSD).

stdio-redir is a small, portable program which uses popen, dup2 and execvp to achieve the same effect.

Basic usage:

$ stdio-redir <stdout-command> <stderr-command> <cmd> <cmd args...>

Example usage correlating to the above Bash code:

$ stdio-redir "logger -p daemon.info" "logger -p daemon.err" some_service -p --param2 param2_value

About

Misc. utils for all sort of stuff

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •