Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
deleted 1 character in body
Source Link
rgov
  • 253
  • 2
  • 14

I was able to achieve this by redirecting output to a fifo, and using the fifo as the input for nc:

#/bin/sh -e

# create a fifo
unlink /tmp/f
mkfifo /tmp/f

# connect to the server in the background
nc localhost 4444 < /tmp/f &

# redirect stdout to the fifo
exec > /tmp/f

# an example that writes to stdout
while [ 1 ];true; do
    sleep 1
    echo "hello world"
done

Note this is only transmitting stdout to the socket; you could add exec 2> /tmp/f to include stderr. I didn't succeed at getting stdin wired up but it should be possible.

(An earlier version of this script swapped nc with exec; this worked on Zsh, but not BusyBox's shell, ash.)

I was able to achieve this by redirecting output to a fifo, and using the fifo as the input for nc:

#/bin/sh -e

# create a fifo
unlink /tmp/f
mkfifo /tmp/f

# connect to the server in the background
nc localhost 4444 < /tmp/f &

# redirect stdout to the fifo
exec > /tmp/f

# an example that writes to stdout
while [ 1 ]; do
    sleep 1
    echo "hello world"
done

Note this is only transmitting stdout to the socket; you could add exec 2> /tmp/f to include stderr. I didn't succeed at getting stdin wired up but it should be possible.

(An earlier version of this script swapped nc with exec; this worked on Zsh, but not BusyBox's shell, ash.)

I was able to achieve this by redirecting output to a fifo, and using the fifo as the input for nc:

#/bin/sh -e

# create a fifo
unlink /tmp/f
mkfifo /tmp/f

# connect to the server in the background
nc localhost 4444 < /tmp/f &

# redirect stdout to the fifo
exec > /tmp/f

# an example that writes to stdout
while true; do
    sleep 1
    echo "hello world"
done

Note this is only transmitting stdout to the socket; you could add exec 2> /tmp/f to include stderr. I didn't succeed at getting stdin wired up but it should be possible.

(An earlier version of this script swapped nc with exec; this worked on Zsh, but not BusyBox's shell, ash.)

edited body
Source Link
rgov
  • 253
  • 2
  • 14

I was able to achieve this by redirecting output to a fifo, and using the fifo as the input for nc:

#/bin/sh -e

# create a fifo
unlink /tmp/f
mkfifo /tmp/f

# redirect stdout to the fifo
exec > /tmp/f

# connect to the server in the background
nc localhost 4444 < /tmp/f &

# redirect stdout to the fifo
exec > /tmp/f

# an example that writes to stdout
while [ 1 ]; do
    sleep 1
    echo "hello world"
done

Note this is only transmitting stdout to the socket; you could add exec 2> /tmp/f to include stderr. I didn't succeed at getting stdin wired up but it should be possible.

(An earlier version of this script swapped nc with exec; this worked on Zsh, but not BusyBox's shell, ash.)

I was able to achieve this by redirecting output to a fifo, and using the fifo as the input for nc:

#/bin/sh -e

# create a fifo
unlink /tmp/f
mkfifo /tmp/f

# redirect stdout to the fifo
exec > /tmp/f

# connect to the server in the background
nc localhost 4444 < /tmp/f &

# an example that writes to stdout
while [ 1 ]; do
    sleep 1
    echo "hello world"
done

Note this is only transmitting stdout to the socket; you could add exec 2> /tmp/f to include stderr. I didn't succeed at getting stdin wired up but it should be possible.

I was able to achieve this by redirecting output to a fifo, and using the fifo as the input for nc:

#/bin/sh -e

# create a fifo
unlink /tmp/f
mkfifo /tmp/f

# connect to the server in the background
nc localhost 4444 < /tmp/f &

# redirect stdout to the fifo
exec > /tmp/f

# an example that writes to stdout
while [ 1 ]; do
    sleep 1
    echo "hello world"
done

Note this is only transmitting stdout to the socket; you could add exec 2> /tmp/f to include stderr. I didn't succeed at getting stdin wired up but it should be possible.

(An earlier version of this script swapped nc with exec; this worked on Zsh, but not BusyBox's shell, ash.)

Source Link
rgov
  • 253
  • 2
  • 14

I was able to achieve this by redirecting output to a fifo, and using the fifo as the input for nc:

#/bin/sh -e

# create a fifo
unlink /tmp/f
mkfifo /tmp/f

# redirect stdout to the fifo
exec > /tmp/f

# connect to the server in the background
nc localhost 4444 < /tmp/f &

# an example that writes to stdout
while [ 1 ]; do
    sleep 1
    echo "hello world"
done

Note this is only transmitting stdout to the socket; you could add exec 2> /tmp/f to include stderr. I didn't succeed at getting stdin wired up but it should be possible.