Skip to main content
reworded for clarity
Source Link
gertvdijk
  • 14.6k
  • 9
  • 49
  • 63

How to send literal string over TCP (netcat/socat-like) without shell or pipe, but provided by command arguments?

If I want to send a string over TCP in a shell environment, I can do something like:

echo text | nc 1.2.3.4 9876

Cool. Interactively, that works. Now I want to do this programmatically by spawning a subprocess from another program, so I want to avoid using a shell and pipes.

But nowAlso, suppose I have asince I'm deploying with distroless Docker environmentcontainers without any shell, thus no echo or pipethey don't come with a shell. 

Is there an existing tool to send an command line argument as string over TCP? I'm looking for aan (imaginary) variant of nc like, e.g.:

nc 1.2.3.4 9876 text

that does the same as the above.

echo text | nc 1.2.3.4 9876

(Need the output too.)

I'm about to write my own application for this, but I can imagine this exists already, simply taking one of the argv instead of stdin to pass on.

Looked at socat, which can read from files with OPEN, which is very close to what I want, but I need the string to be passed as parameter from the command lineissued.

For the full context, the entrypoint of the Docker container should be settable by it, without shells or other interpreted language, but pure OS native dependencies like glibc (like socat/nc is!).

How to send literal string over TCP (netcat/socat) without shell or pipe?

If I want to send a string over TCP in a shell environment, I can do something like:

echo text | nc 1.2.3.4 9876

Cool.

But now, suppose I have a distroless Docker environment without any shell, thus no echo or pipe. Is there an existing tool to send an command line argument as string over TCP? I'm looking for a variant of nc like e.g.:

nc 1.2.3.4 9876 text

that does the same as the above. (Need the output too.)

I'm about to write my own application for this, but I can imagine this exists already.

Looked at socat, which can read from files with OPEN, which is very close to what I want, but I need the parameter from the command line.

How to send literal string over TCP (netcat/socat-like), but provided by command arguments?

If I want to send a string over TCP in a shell environment, I can do something like:

echo text | nc 1.2.3.4 9876

Cool. Interactively, that works. Now I want to do this programmatically by spawning a subprocess from another program, so I want to avoid using a shell and pipes.

Also, since I'm deploying with distroless Docker containers, they don't come with a shell. 

Is there an existing tool to send an command argument as string over TCP? I'm looking for an (imaginary) variant of nc, e.g.:

nc 1.2.3.4 9876 text

that does the same as

echo text | nc 1.2.3.4 9876

(Need the output too.)

I'm about to write my own application for this, but I can imagine this exists already, simply taking one of the argv instead of stdin to pass on.

Looked at socat, which can read from files with OPEN, which is very close to what I want, but I need the string to be passed as parameter from the command issued.

For the full context, the entrypoint of the Docker container should be settable by it, without shells or other interpreted language, but pure OS native dependencies like glibc (like socat/nc is!).

add link to distroless
Source Link
gertvdijk
  • 14.6k
  • 9
  • 49
  • 63

If I want to send a string over TCP in a shell environment, I can do something like:

echo text | nc 1.2.3.4 9876

Cool.

But now, suppose I have a distroless Docker environmentdistroless Docker environment without any shell, thus no echo or pipe. Is there an existing tool to send an command line argument as string over TCP? I'm looking for a variant of nc like e.g.:

nc 1.2.3.4 9876 text

that does the same as the above. (Need the output too.)

I'm about to write my own application for this, but I can imagine this exists already.

Looked at socat, which can read from files with OPEN, which is very close to what I want, but I need the parameter from the command line.

If I want to send a string over TCP in a shell environment, I can do something like:

echo text | nc 1.2.3.4 9876

Cool.

But now, suppose I have a distroless Docker environment without any shell, thus no echo or pipe. Is there an existing tool to send an command line argument as string over TCP? I'm looking for a variant of nc like e.g.:

nc 1.2.3.4 9876 text

that does the same as the above. (Need the output too.)

I'm about to write my own application for this, but I can imagine this exists already.

Looked at socat, which can read from files with OPEN, which is very close to what I want, but I need the parameter from the command line.

If I want to send a string over TCP in a shell environment, I can do something like:

echo text | nc 1.2.3.4 9876

Cool.

But now, suppose I have a distroless Docker environment without any shell, thus no echo or pipe. Is there an existing tool to send an command line argument as string over TCP? I'm looking for a variant of nc like e.g.:

nc 1.2.3.4 9876 text

that does the same as the above. (Need the output too.)

I'm about to write my own application for this, but I can imagine this exists already.

Looked at socat, which can read from files with OPEN, which is very close to what I want, but I need the parameter from the command line.

deleted 17 characters in body
Source Link
Rui F Ribeiro
  • 58k
  • 28
  • 156
  • 239

If I want to send a string over TCP in a shell environment, I can do something like:

echo text | nc 1.2.3.4 9876

Cool.

But now, suppose I have a distroless Docker environment without any shell, thus no echo or pipe. Is there an existing tool to send an command line argument as string over TCP? I'm looking for a variant of nc like e.g.:

nc 1.2.3.4 9876 text

that does the same as the above. (Need the output too, if that matters.)

I'm about to write my own application for this, but I can imagine this exists already.

Looked at socat, which can read from files with OPEN, which is very close to what I want, but I need the parameter from the command line.

If I want to send a string over TCP in a shell environment, I can do something like:

echo text | nc 1.2.3.4 9876

Cool.

But now, suppose I have a distroless Docker environment without any shell, thus no echo or pipe. Is there an existing tool to send an command line argument as string over TCP? I'm looking for a variant of nc like e.g.:

nc 1.2.3.4 9876 text

that does the same as the above. (Need the output too, if that matters.)

I'm about to write my own application for this, but I can imagine this exists already.

Looked at socat, which can read from files with OPEN, which is very close to what I want, but I need the parameter from the command line.

If I want to send a string over TCP in a shell environment, I can do something like:

echo text | nc 1.2.3.4 9876

Cool.

But now, suppose I have a distroless Docker environment without any shell, thus no echo or pipe. Is there an existing tool to send an command line argument as string over TCP? I'm looking for a variant of nc like e.g.:

nc 1.2.3.4 9876 text

that does the same as the above. (Need the output too.)

I'm about to write my own application for this, but I can imagine this exists already.

Looked at socat, which can read from files with OPEN, which is very close to what I want, but I need the parameter from the command line.

Source Link
gertvdijk
  • 14.6k
  • 9
  • 49
  • 63
Loading