How to send literal string over TCP (netcat/socat-like), but provided by command arguments?socat reliable file transfer over TCPLinux Shell Script - Send command over TCP to Sharp AquosCommand line streaming string manipulation from netcatHow to record an interactice socat TCP/TLS session?Expose awk over tcp (inetd, socat, etc.)Using socat to Tunnel/Proxy TCP want to split send/receive into separate filesCreate UDP to TCP bridge with socat/netcat to relay control commands for vlc media-playerWhich layer(IP/TCP?) is netcat/socat working on?Can I resume a failed (ZoL) ZFS send over netcat?socat - UNIX-LISTEN and TCP-LISTEN in one command

I'm in charge of equipment buying but no one's ever happy with what I choose. How to fix this?

Escape a backup date in a file name

System.debug(JSON.Serialize(o)) Not longer shows full string

Two monoidal structures and copowering

Why not increase contact surface when reentering the atmosphere?

Unreliable Magic - Is it worth it?

Is a stroke of luck acceptable after a series of unfavorable events?

Is the destination of a commercial flight important for the pilot?

How can I kill an app using Terminal?

Tiptoe or tiphoof? Adjusting words to better fit fantasy races

Is HostGator storing my password in plaintext?

Would a high gravity rocky planet be guaranteed to have an atmosphere?

How to run a prison with the smallest amount of guards?

Large drywall patch supports

What is the difference between "behavior" and "behaviour"?

How to Reset Passwords on Multiple Websites Easily?

Pole-zeros of a real-valued causal FIR system

How to write papers efficiently when English isn't my first language?

Anatomically Correct Strange Women In Ponds Distributing Swords

Integer addition + constant, is it a group?

How does it work when somebody invests in my business?

How can I get through very long and very dry, but also very useful technical documents when learning a new tool?

How does Loki do this?

India just shot down a satellite from the ground. At what altitude range is the resulting debris field?



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


socat reliable file transfer over TCPLinux Shell Script - Send command over TCP to Sharp AquosCommand line streaming string manipulation from netcatHow to record an interactice socat TCP/TLS session?Expose awk over tcp (inetd, socat, etc.)Using socat to Tunnel/Proxy TCP want to split send/receive into separate filesCreate UDP to TCP bridge with socat/netcat to relay control commands for vlc media-playerWhich layer(IP/TCP?) is netcat/socat working on?Can I resume a failed (ZoL) ZFS send over netcat?socat - UNIX-LISTEN and TCP-LISTEN in one command













-1















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!).










share|improve this question



















  • 2





    If you haven't got a shell, what are you expecting to run your command ?

    – X Tian
    yesterday











  • you must have somekind of shell if you can run netcat inside your docker. Don't you have access to busybox echo or busybox cat commands ?

    – Kiwy
    yesterday











  • @XTian Uhm, you can run commands without a shell! In fact, that's what best practice in containerized environments. E.g. ENTRYPOINT ["/bin/sh", "-c", "mycommand"] is unnecessary, just do ENTRYPOINT ["mycommand"]. Also more generally, when processes spawn other processes, you don't want to invoke a full shell, see e.g. man 2 execve.

    – gertvdijk
    yesterday






  • 1





    Please read your question you need to use | to execute your command, pipe is part of the shell so you either need a shell/bash/zsh to execute your command either you develop a module to nc to allow the use of a file as an argument. So if you have a busybox inside you can use busybox sh. Distroless is oriented toward application execution so you could either use a python application to do what you want stackoverflow.com/q/1908878/1195001 or use an other docker image as it seems this one doesn't fulfil your goal.

    – Kiwy
    yesterday






  • 2





    So you have some restriction on the collection of programs available in your docker environment, and you want someone to guess which of those programs can do the work of reading from a socket and writing to it, and also spawning some other program. It would then help if you then tell which programs you do have rather then telling some you don't have.

    – Ralph Rönnquist
    yesterday















-1















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!).










share|improve this question



















  • 2





    If you haven't got a shell, what are you expecting to run your command ?

    – X Tian
    yesterday











  • you must have somekind of shell if you can run netcat inside your docker. Don't you have access to busybox echo or busybox cat commands ?

    – Kiwy
    yesterday











  • @XTian Uhm, you can run commands without a shell! In fact, that's what best practice in containerized environments. E.g. ENTRYPOINT ["/bin/sh", "-c", "mycommand"] is unnecessary, just do ENTRYPOINT ["mycommand"]. Also more generally, when processes spawn other processes, you don't want to invoke a full shell, see e.g. man 2 execve.

    – gertvdijk
    yesterday






  • 1





    Please read your question you need to use | to execute your command, pipe is part of the shell so you either need a shell/bash/zsh to execute your command either you develop a module to nc to allow the use of a file as an argument. So if you have a busybox inside you can use busybox sh. Distroless is oriented toward application execution so you could either use a python application to do what you want stackoverflow.com/q/1908878/1195001 or use an other docker image as it seems this one doesn't fulfil your goal.

    – Kiwy
    yesterday






  • 2





    So you have some restriction on the collection of programs available in your docker environment, and you want someone to guess which of those programs can do the work of reading from a socket and writing to it, and also spawning some other program. It would then help if you then tell which programs you do have rather then telling some you don't have.

    – Ralph Rönnquist
    yesterday













-1












-1








-1








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!).










share|improve this question
















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!).







tcp socket netcat socat






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited yesterday







gertvdijk

















asked yesterday









gertvdijkgertvdijk

7,49252945




7,49252945







  • 2





    If you haven't got a shell, what are you expecting to run your command ?

    – X Tian
    yesterday











  • you must have somekind of shell if you can run netcat inside your docker. Don't you have access to busybox echo or busybox cat commands ?

    – Kiwy
    yesterday











  • @XTian Uhm, you can run commands without a shell! In fact, that's what best practice in containerized environments. E.g. ENTRYPOINT ["/bin/sh", "-c", "mycommand"] is unnecessary, just do ENTRYPOINT ["mycommand"]. Also more generally, when processes spawn other processes, you don't want to invoke a full shell, see e.g. man 2 execve.

    – gertvdijk
    yesterday






  • 1





    Please read your question you need to use | to execute your command, pipe is part of the shell so you either need a shell/bash/zsh to execute your command either you develop a module to nc to allow the use of a file as an argument. So if you have a busybox inside you can use busybox sh. Distroless is oriented toward application execution so you could either use a python application to do what you want stackoverflow.com/q/1908878/1195001 or use an other docker image as it seems this one doesn't fulfil your goal.

    – Kiwy
    yesterday






  • 2





    So you have some restriction on the collection of programs available in your docker environment, and you want someone to guess which of those programs can do the work of reading from a socket and writing to it, and also spawning some other program. It would then help if you then tell which programs you do have rather then telling some you don't have.

    – Ralph Rönnquist
    yesterday












  • 2





    If you haven't got a shell, what are you expecting to run your command ?

    – X Tian
    yesterday











  • you must have somekind of shell if you can run netcat inside your docker. Don't you have access to busybox echo or busybox cat commands ?

    – Kiwy
    yesterday











  • @XTian Uhm, you can run commands without a shell! In fact, that's what best practice in containerized environments. E.g. ENTRYPOINT ["/bin/sh", "-c", "mycommand"] is unnecessary, just do ENTRYPOINT ["mycommand"]. Also more generally, when processes spawn other processes, you don't want to invoke a full shell, see e.g. man 2 execve.

    – gertvdijk
    yesterday






  • 1





    Please read your question you need to use | to execute your command, pipe is part of the shell so you either need a shell/bash/zsh to execute your command either you develop a module to nc to allow the use of a file as an argument. So if you have a busybox inside you can use busybox sh. Distroless is oriented toward application execution so you could either use a python application to do what you want stackoverflow.com/q/1908878/1195001 or use an other docker image as it seems this one doesn't fulfil your goal.

    – Kiwy
    yesterday






  • 2





    So you have some restriction on the collection of programs available in your docker environment, and you want someone to guess which of those programs can do the work of reading from a socket and writing to it, and also spawning some other program. It would then help if you then tell which programs you do have rather then telling some you don't have.

    – Ralph Rönnquist
    yesterday







2




2





If you haven't got a shell, what are you expecting to run your command ?

– X Tian
yesterday





If you haven't got a shell, what are you expecting to run your command ?

– X Tian
yesterday













you must have somekind of shell if you can run netcat inside your docker. Don't you have access to busybox echo or busybox cat commands ?

– Kiwy
yesterday





you must have somekind of shell if you can run netcat inside your docker. Don't you have access to busybox echo or busybox cat commands ?

– Kiwy
yesterday













@XTian Uhm, you can run commands without a shell! In fact, that's what best practice in containerized environments. E.g. ENTRYPOINT ["/bin/sh", "-c", "mycommand"] is unnecessary, just do ENTRYPOINT ["mycommand"]. Also more generally, when processes spawn other processes, you don't want to invoke a full shell, see e.g. man 2 execve.

– gertvdijk
yesterday





@XTian Uhm, you can run commands without a shell! In fact, that's what best practice in containerized environments. E.g. ENTRYPOINT ["/bin/sh", "-c", "mycommand"] is unnecessary, just do ENTRYPOINT ["mycommand"]. Also more generally, when processes spawn other processes, you don't want to invoke a full shell, see e.g. man 2 execve.

– gertvdijk
yesterday




1




1





Please read your question you need to use | to execute your command, pipe is part of the shell so you either need a shell/bash/zsh to execute your command either you develop a module to nc to allow the use of a file as an argument. So if you have a busybox inside you can use busybox sh. Distroless is oriented toward application execution so you could either use a python application to do what you want stackoverflow.com/q/1908878/1195001 or use an other docker image as it seems this one doesn't fulfil your goal.

– Kiwy
yesterday





Please read your question you need to use | to execute your command, pipe is part of the shell so you either need a shell/bash/zsh to execute your command either you develop a module to nc to allow the use of a file as an argument. So if you have a busybox inside you can use busybox sh. Distroless is oriented toward application execution so you could either use a python application to do what you want stackoverflow.com/q/1908878/1195001 or use an other docker image as it seems this one doesn't fulfil your goal.

– Kiwy
yesterday




2




2





So you have some restriction on the collection of programs available in your docker environment, and you want someone to guess which of those programs can do the work of reading from a socket and writing to it, and also spawning some other program. It would then help if you then tell which programs you do have rather then telling some you don't have.

– Ralph Rönnquist
yesterday





So you have some restriction on the collection of programs available in your docker environment, and you want someone to guess which of those programs can do the work of reading from a socket and writing to it, and also spawning some other program. It would then help if you then tell which programs you do have rather then telling some you don't have.

– Ralph Rönnquist
yesterday










3 Answers
3






active

oldest

votes


















1














I don't know of any program that takes a parameter and sends it over a tcp connection.



However you have sort of answered your own question somewhat within your comments, specifically with the following line.



ENTRYPOINT ["/bin/sh", "-c", "mycommand"]


I appreciate that you seem to want the minimalist footprint of applications in your image, but I believe the best solution is to have a shell and netcat., then use your original command. Well at least to test whatever you are trying to do.



If at the end of the day, you want to drop back to only one executable, you'll have to write your own program to do it.



One thought, I see this example, shows setup of Python to run a script,



FROM python:2.7-slim AS build-env
ADD . /app
WORKDIR /app

FROM gcr.io/distroless/python2.7
COPY --from=build-env /app /app
WORKDIR /app
CMD ["hello.py", "/etc"]


which might be easier/quicker than developing a C program to do it all, but then effectively you are using Python as the SHELL. Lastly, if you think socat would do what you want, could you use socat to read from a file (which you include in your image), and that file contains your literal string.






share|improve this answer

























  • This is not an answer to my question, sorry. I was asking if there was a program already that implements the 10 lines of C code to write arguments to a socket, instead stdin.

    – gertvdijk
    yesterday











  • I started my answer saying I don't think there is such a program, and then went on to suggest alternative solutions. I also think having a couple of utilities (shell, php, busbox) still constitutes a distroless container, minimising the the available targets.

    – X Tian
    yesterday



















0














I've written my own small application to implement what I need. Reads arguments and writes them to a socket. Too bad that it didn't exist yet, but only more complicated features are available in tools like nc and socat. Perhaps I might find time to write a patch to nc to also accept input from an argument.



Re comments - I find it a bit sad to read including a full shell and spawning subprocesses from it is the new norm. Pure overhead we don't need.






share|improve this answer

























  • Instead of writing such a narrow utililty, you could've written a wrapper that "transforms" some command line arguments into a file and then exec's another program with its stdin redirected from it. Simple POC (linux-only) here. You can use it as herestring text nc -N host port. (that will not append a newline to text, unlike echo text).

    – mosvy
    yesterday


















0














I suppose you could use newlisp, such as



newlisp -e '(write-line (net-connect "localhost" 3456) "go for it")'


and vary parameters as desired.



I'm pretty sure you could use perl or other interpreters as well, though newlisp is quite small and it can be compiled into a static program as well.



The above example will make the program connect to localhost port 3456, and issue the line go for it on the socket, then it will exit. Goto the newlisp home site for more details.






share|improve this answer























  • JRE ?? Not sure where you got that one from.

    – Ralph Rönnquist
    yesterday











  • newlisp.org/index.cgi?Downloads shows a JRE dependency to me?

    – gertvdijk
    yesterday











  • It's a bit of bad advertising, I think :) Of course one can run newlisp with a Java process as a front-end, if it's too hard to do terminal interaction. But that is newlisp plus a front-end. You don't want/need a front-end, esp. as you want to execute only the command line script.

    – Ralph Rönnquist
    yesterday











  • Oh, yeah I see it now. The JRE is for development. I see that the actual binary is quite lightweight, thanks. Still, some libreadline I see I don't have in the container, but yeah, close enough for an answer!

    – gertvdijk
    yesterday











  • Yes. Normal build requires libreadline, libffi and libdl. Though it's quite easy to build a binary without needing any of them (and lose the related functionality of course). Ask at newlispfanclub.alh.net if you need.

    – Ralph Rönnquist
    yesterday











Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f508688%2fhow-to-send-literal-string-over-tcp-netcat-socat-like-but-provided-by-command%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























3 Answers
3






active

oldest

votes








3 Answers
3






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














I don't know of any program that takes a parameter and sends it over a tcp connection.



However you have sort of answered your own question somewhat within your comments, specifically with the following line.



ENTRYPOINT ["/bin/sh", "-c", "mycommand"]


I appreciate that you seem to want the minimalist footprint of applications in your image, but I believe the best solution is to have a shell and netcat., then use your original command. Well at least to test whatever you are trying to do.



If at the end of the day, you want to drop back to only one executable, you'll have to write your own program to do it.



One thought, I see this example, shows setup of Python to run a script,



FROM python:2.7-slim AS build-env
ADD . /app
WORKDIR /app

FROM gcr.io/distroless/python2.7
COPY --from=build-env /app /app
WORKDIR /app
CMD ["hello.py", "/etc"]


which might be easier/quicker than developing a C program to do it all, but then effectively you are using Python as the SHELL. Lastly, if you think socat would do what you want, could you use socat to read from a file (which you include in your image), and that file contains your literal string.






share|improve this answer

























  • This is not an answer to my question, sorry. I was asking if there was a program already that implements the 10 lines of C code to write arguments to a socket, instead stdin.

    – gertvdijk
    yesterday











  • I started my answer saying I don't think there is such a program, and then went on to suggest alternative solutions. I also think having a couple of utilities (shell, php, busbox) still constitutes a distroless container, minimising the the available targets.

    – X Tian
    yesterday
















1














I don't know of any program that takes a parameter and sends it over a tcp connection.



However you have sort of answered your own question somewhat within your comments, specifically with the following line.



ENTRYPOINT ["/bin/sh", "-c", "mycommand"]


I appreciate that you seem to want the minimalist footprint of applications in your image, but I believe the best solution is to have a shell and netcat., then use your original command. Well at least to test whatever you are trying to do.



If at the end of the day, you want to drop back to only one executable, you'll have to write your own program to do it.



One thought, I see this example, shows setup of Python to run a script,



FROM python:2.7-slim AS build-env
ADD . /app
WORKDIR /app

FROM gcr.io/distroless/python2.7
COPY --from=build-env /app /app
WORKDIR /app
CMD ["hello.py", "/etc"]


which might be easier/quicker than developing a C program to do it all, but then effectively you are using Python as the SHELL. Lastly, if you think socat would do what you want, could you use socat to read from a file (which you include in your image), and that file contains your literal string.






share|improve this answer

























  • This is not an answer to my question, sorry. I was asking if there was a program already that implements the 10 lines of C code to write arguments to a socket, instead stdin.

    – gertvdijk
    yesterday











  • I started my answer saying I don't think there is such a program, and then went on to suggest alternative solutions. I also think having a couple of utilities (shell, php, busbox) still constitutes a distroless container, minimising the the available targets.

    – X Tian
    yesterday














1












1








1







I don't know of any program that takes a parameter and sends it over a tcp connection.



However you have sort of answered your own question somewhat within your comments, specifically with the following line.



ENTRYPOINT ["/bin/sh", "-c", "mycommand"]


I appreciate that you seem to want the minimalist footprint of applications in your image, but I believe the best solution is to have a shell and netcat., then use your original command. Well at least to test whatever you are trying to do.



If at the end of the day, you want to drop back to only one executable, you'll have to write your own program to do it.



One thought, I see this example, shows setup of Python to run a script,



FROM python:2.7-slim AS build-env
ADD . /app
WORKDIR /app

FROM gcr.io/distroless/python2.7
COPY --from=build-env /app /app
WORKDIR /app
CMD ["hello.py", "/etc"]


which might be easier/quicker than developing a C program to do it all, but then effectively you are using Python as the SHELL. Lastly, if you think socat would do what you want, could you use socat to read from a file (which you include in your image), and that file contains your literal string.






share|improve this answer















I don't know of any program that takes a parameter and sends it over a tcp connection.



However you have sort of answered your own question somewhat within your comments, specifically with the following line.



ENTRYPOINT ["/bin/sh", "-c", "mycommand"]


I appreciate that you seem to want the minimalist footprint of applications in your image, but I believe the best solution is to have a shell and netcat., then use your original command. Well at least to test whatever you are trying to do.



If at the end of the day, you want to drop back to only one executable, you'll have to write your own program to do it.



One thought, I see this example, shows setup of Python to run a script,



FROM python:2.7-slim AS build-env
ADD . /app
WORKDIR /app

FROM gcr.io/distroless/python2.7
COPY --from=build-env /app /app
WORKDIR /app
CMD ["hello.py", "/etc"]


which might be easier/quicker than developing a C program to do it all, but then effectively you are using Python as the SHELL. Lastly, if you think socat would do what you want, could you use socat to read from a file (which you include in your image), and that file contains your literal string.







share|improve this answer














share|improve this answer



share|improve this answer








edited yesterday









sourcejedi

25.5k445110




25.5k445110










answered yesterday









X TianX Tian

7,78112237




7,78112237












  • This is not an answer to my question, sorry. I was asking if there was a program already that implements the 10 lines of C code to write arguments to a socket, instead stdin.

    – gertvdijk
    yesterday











  • I started my answer saying I don't think there is such a program, and then went on to suggest alternative solutions. I also think having a couple of utilities (shell, php, busbox) still constitutes a distroless container, minimising the the available targets.

    – X Tian
    yesterday


















  • This is not an answer to my question, sorry. I was asking if there was a program already that implements the 10 lines of C code to write arguments to a socket, instead stdin.

    – gertvdijk
    yesterday











  • I started my answer saying I don't think there is such a program, and then went on to suggest alternative solutions. I also think having a couple of utilities (shell, php, busbox) still constitutes a distroless container, minimising the the available targets.

    – X Tian
    yesterday

















This is not an answer to my question, sorry. I was asking if there was a program already that implements the 10 lines of C code to write arguments to a socket, instead stdin.

– gertvdijk
yesterday





This is not an answer to my question, sorry. I was asking if there was a program already that implements the 10 lines of C code to write arguments to a socket, instead stdin.

– gertvdijk
yesterday













I started my answer saying I don't think there is such a program, and then went on to suggest alternative solutions. I also think having a couple of utilities (shell, php, busbox) still constitutes a distroless container, minimising the the available targets.

– X Tian
yesterday






I started my answer saying I don't think there is such a program, and then went on to suggest alternative solutions. I also think having a couple of utilities (shell, php, busbox) still constitutes a distroless container, minimising the the available targets.

– X Tian
yesterday














0














I've written my own small application to implement what I need. Reads arguments and writes them to a socket. Too bad that it didn't exist yet, but only more complicated features are available in tools like nc and socat. Perhaps I might find time to write a patch to nc to also accept input from an argument.



Re comments - I find it a bit sad to read including a full shell and spawning subprocesses from it is the new norm. Pure overhead we don't need.






share|improve this answer

























  • Instead of writing such a narrow utililty, you could've written a wrapper that "transforms" some command line arguments into a file and then exec's another program with its stdin redirected from it. Simple POC (linux-only) here. You can use it as herestring text nc -N host port. (that will not append a newline to text, unlike echo text).

    – mosvy
    yesterday















0














I've written my own small application to implement what I need. Reads arguments and writes them to a socket. Too bad that it didn't exist yet, but only more complicated features are available in tools like nc and socat. Perhaps I might find time to write a patch to nc to also accept input from an argument.



Re comments - I find it a bit sad to read including a full shell and spawning subprocesses from it is the new norm. Pure overhead we don't need.






share|improve this answer

























  • Instead of writing such a narrow utililty, you could've written a wrapper that "transforms" some command line arguments into a file and then exec's another program with its stdin redirected from it. Simple POC (linux-only) here. You can use it as herestring text nc -N host port. (that will not append a newline to text, unlike echo text).

    – mosvy
    yesterday













0












0








0







I've written my own small application to implement what I need. Reads arguments and writes them to a socket. Too bad that it didn't exist yet, but only more complicated features are available in tools like nc and socat. Perhaps I might find time to write a patch to nc to also accept input from an argument.



Re comments - I find it a bit sad to read including a full shell and spawning subprocesses from it is the new norm. Pure overhead we don't need.






share|improve this answer















I've written my own small application to implement what I need. Reads arguments and writes them to a socket. Too bad that it didn't exist yet, but only more complicated features are available in tools like nc and socat. Perhaps I might find time to write a patch to nc to also accept input from an argument.



Re comments - I find it a bit sad to read including a full shell and spawning subprocesses from it is the new norm. Pure overhead we don't need.







share|improve this answer














share|improve this answer



share|improve this answer








edited yesterday

























answered yesterday









gertvdijkgertvdijk

7,49252945




7,49252945












  • Instead of writing such a narrow utililty, you could've written a wrapper that "transforms" some command line arguments into a file and then exec's another program with its stdin redirected from it. Simple POC (linux-only) here. You can use it as herestring text nc -N host port. (that will not append a newline to text, unlike echo text).

    – mosvy
    yesterday

















  • Instead of writing such a narrow utililty, you could've written a wrapper that "transforms" some command line arguments into a file and then exec's another program with its stdin redirected from it. Simple POC (linux-only) here. You can use it as herestring text nc -N host port. (that will not append a newline to text, unlike echo text).

    – mosvy
    yesterday
















Instead of writing such a narrow utililty, you could've written a wrapper that "transforms" some command line arguments into a file and then exec's another program with its stdin redirected from it. Simple POC (linux-only) here. You can use it as herestring text nc -N host port. (that will not append a newline to text, unlike echo text).

– mosvy
yesterday





Instead of writing such a narrow utililty, you could've written a wrapper that "transforms" some command line arguments into a file and then exec's another program with its stdin redirected from it. Simple POC (linux-only) here. You can use it as herestring text nc -N host port. (that will not append a newline to text, unlike echo text).

– mosvy
yesterday











0














I suppose you could use newlisp, such as



newlisp -e '(write-line (net-connect "localhost" 3456) "go for it")'


and vary parameters as desired.



I'm pretty sure you could use perl or other interpreters as well, though newlisp is quite small and it can be compiled into a static program as well.



The above example will make the program connect to localhost port 3456, and issue the line go for it on the socket, then it will exit. Goto the newlisp home site for more details.






share|improve this answer























  • JRE ?? Not sure where you got that one from.

    – Ralph Rönnquist
    yesterday











  • newlisp.org/index.cgi?Downloads shows a JRE dependency to me?

    – gertvdijk
    yesterday











  • It's a bit of bad advertising, I think :) Of course one can run newlisp with a Java process as a front-end, if it's too hard to do terminal interaction. But that is newlisp plus a front-end. You don't want/need a front-end, esp. as you want to execute only the command line script.

    – Ralph Rönnquist
    yesterday











  • Oh, yeah I see it now. The JRE is for development. I see that the actual binary is quite lightweight, thanks. Still, some libreadline I see I don't have in the container, but yeah, close enough for an answer!

    – gertvdijk
    yesterday











  • Yes. Normal build requires libreadline, libffi and libdl. Though it's quite easy to build a binary without needing any of them (and lose the related functionality of course). Ask at newlispfanclub.alh.net if you need.

    – Ralph Rönnquist
    yesterday
















0














I suppose you could use newlisp, such as



newlisp -e '(write-line (net-connect "localhost" 3456) "go for it")'


and vary parameters as desired.



I'm pretty sure you could use perl or other interpreters as well, though newlisp is quite small and it can be compiled into a static program as well.



The above example will make the program connect to localhost port 3456, and issue the line go for it on the socket, then it will exit. Goto the newlisp home site for more details.






share|improve this answer























  • JRE ?? Not sure where you got that one from.

    – Ralph Rönnquist
    yesterday











  • newlisp.org/index.cgi?Downloads shows a JRE dependency to me?

    – gertvdijk
    yesterday











  • It's a bit of bad advertising, I think :) Of course one can run newlisp with a Java process as a front-end, if it's too hard to do terminal interaction. But that is newlisp plus a front-end. You don't want/need a front-end, esp. as you want to execute only the command line script.

    – Ralph Rönnquist
    yesterday











  • Oh, yeah I see it now. The JRE is for development. I see that the actual binary is quite lightweight, thanks. Still, some libreadline I see I don't have in the container, but yeah, close enough for an answer!

    – gertvdijk
    yesterday











  • Yes. Normal build requires libreadline, libffi and libdl. Though it's quite easy to build a binary without needing any of them (and lose the related functionality of course). Ask at newlispfanclub.alh.net if you need.

    – Ralph Rönnquist
    yesterday














0












0








0







I suppose you could use newlisp, such as



newlisp -e '(write-line (net-connect "localhost" 3456) "go for it")'


and vary parameters as desired.



I'm pretty sure you could use perl or other interpreters as well, though newlisp is quite small and it can be compiled into a static program as well.



The above example will make the program connect to localhost port 3456, and issue the line go for it on the socket, then it will exit. Goto the newlisp home site for more details.






share|improve this answer













I suppose you could use newlisp, such as



newlisp -e '(write-line (net-connect "localhost" 3456) "go for it")'


and vary parameters as desired.



I'm pretty sure you could use perl or other interpreters as well, though newlisp is quite small and it can be compiled into a static program as well.



The above example will make the program connect to localhost port 3456, and issue the line go for it on the socket, then it will exit. Goto the newlisp home site for more details.







share|improve this answer












share|improve this answer



share|improve this answer










answered yesterday









Ralph RönnquistRalph Rönnquist

2,69759




2,69759












  • JRE ?? Not sure where you got that one from.

    – Ralph Rönnquist
    yesterday











  • newlisp.org/index.cgi?Downloads shows a JRE dependency to me?

    – gertvdijk
    yesterday











  • It's a bit of bad advertising, I think :) Of course one can run newlisp with a Java process as a front-end, if it's too hard to do terminal interaction. But that is newlisp plus a front-end. You don't want/need a front-end, esp. as you want to execute only the command line script.

    – Ralph Rönnquist
    yesterday











  • Oh, yeah I see it now. The JRE is for development. I see that the actual binary is quite lightweight, thanks. Still, some libreadline I see I don't have in the container, but yeah, close enough for an answer!

    – gertvdijk
    yesterday











  • Yes. Normal build requires libreadline, libffi and libdl. Though it's quite easy to build a binary without needing any of them (and lose the related functionality of course). Ask at newlispfanclub.alh.net if you need.

    – Ralph Rönnquist
    yesterday


















  • JRE ?? Not sure where you got that one from.

    – Ralph Rönnquist
    yesterday











  • newlisp.org/index.cgi?Downloads shows a JRE dependency to me?

    – gertvdijk
    yesterday











  • It's a bit of bad advertising, I think :) Of course one can run newlisp with a Java process as a front-end, if it's too hard to do terminal interaction. But that is newlisp plus a front-end. You don't want/need a front-end, esp. as you want to execute only the command line script.

    – Ralph Rönnquist
    yesterday











  • Oh, yeah I see it now. The JRE is for development. I see that the actual binary is quite lightweight, thanks. Still, some libreadline I see I don't have in the container, but yeah, close enough for an answer!

    – gertvdijk
    yesterday











  • Yes. Normal build requires libreadline, libffi and libdl. Though it's quite easy to build a binary without needing any of them (and lose the related functionality of course). Ask at newlispfanclub.alh.net if you need.

    – Ralph Rönnquist
    yesterday

















JRE ?? Not sure where you got that one from.

– Ralph Rönnquist
yesterday





JRE ?? Not sure where you got that one from.

– Ralph Rönnquist
yesterday













newlisp.org/index.cgi?Downloads shows a JRE dependency to me?

– gertvdijk
yesterday





newlisp.org/index.cgi?Downloads shows a JRE dependency to me?

– gertvdijk
yesterday













It's a bit of bad advertising, I think :) Of course one can run newlisp with a Java process as a front-end, if it's too hard to do terminal interaction. But that is newlisp plus a front-end. You don't want/need a front-end, esp. as you want to execute only the command line script.

– Ralph Rönnquist
yesterday





It's a bit of bad advertising, I think :) Of course one can run newlisp with a Java process as a front-end, if it's too hard to do terminal interaction. But that is newlisp plus a front-end. You don't want/need a front-end, esp. as you want to execute only the command line script.

– Ralph Rönnquist
yesterday













Oh, yeah I see it now. The JRE is for development. I see that the actual binary is quite lightweight, thanks. Still, some libreadline I see I don't have in the container, but yeah, close enough for an answer!

– gertvdijk
yesterday





Oh, yeah I see it now. The JRE is for development. I see that the actual binary is quite lightweight, thanks. Still, some libreadline I see I don't have in the container, but yeah, close enough for an answer!

– gertvdijk
yesterday













Yes. Normal build requires libreadline, libffi and libdl. Though it's quite easy to build a binary without needing any of them (and lose the related functionality of course). Ask at newlispfanclub.alh.net if you need.

– Ralph Rönnquist
yesterday






Yes. Normal build requires libreadline, libffi and libdl. Though it's quite easy to build a binary without needing any of them (and lose the related functionality of course). Ask at newlispfanclub.alh.net if you need.

– Ralph Rönnquist
yesterday


















draft saved

draft discarded
















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f508688%2fhow-to-send-literal-string-over-tcp-netcat-socat-like-but-provided-by-command%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

getting Checkpoint VPN SSL Network Extender working in the command lineHow to connect to CheckPoint VPN on Ubuntu 18.04LTS?Will the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayVPN SSL Network Extender in FirefoxLinux Checkpoint SNX tool configuration issuesCheck Point - Connect under Linux - snx + OTPSNX VPN Ububuntu 18.XXUsing Checkpoint VPN SSL Network Extender CLI with certificateVPN with network manager (nm-applet) is not workingWill the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayImport VPN config files to NetworkManager from command lineTrouble connecting to VPN using network-manager, while command line worksStart a VPN connection with PPTP protocol on command linestarting a docker service daemon breaks the vpn networkCan't connect to vpn with Network-managerVPN SSL Network Extender in FirefoxUsing Checkpoint VPN SSL Network Extender CLI with certificate

Cannot Extend partition with GParted The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) 2019 Community Moderator Election ResultsCan't increase partition size with GParted?GParted doesn't recognize the unallocated space after my current partitionWhat is the best way to add unallocated space located before to Ubuntu 12.04 partition with GParted live?I can't figure out how to extend my Arch home partition into free spaceGparted Linux Mint 18.1 issueTrying to extend but swap partition is showing as Unknown in Gparted, shows proper from fdiskRearrange partitions in gparted to extend a partitionUnable to extend partition even though unallocated space is next to it using GPartedAllocate free space to root partitiongparted: how to merge unallocated space with a partition

Marilyn Monroe Ny fiainany manokana | Jereo koa | Meny fitetezanafanitarana azy.