Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to devise a one-liner to send text to a simple echo server - but multiple connections in parallel. This is what I'm trying:

echo -e  A,B,C,D | xargs -d, -i -P 4 echo {} |  nc localhost 7000

However, it doesn't quite work. The server receives four connections but no data ("null").

What is the correct xargs and netcat command here?

share|improve this question

The answer is to use sh -c to launch xargs:

echo 'A,B,C,D' | xargs -d, -i -P 4 sh -c 'echo "{}" | nc localhost 7000'


share|improve this answer

Use echo -n or you will get 5 connections instead four, one of them with no data. If in the server this is not checked, maybe it is causing your problem.

echo -n A,B,C,D | xargs -d, -I{} -P 4 -n 1 echo {} | nc localhost 7000

Moreover, using a netcat as listening server, it appears to work right:

zhen@sydow:~$ nc -l 7000

And also it seems to be parallel, I see out-of-order echo.

share|improve this answer

You don't need to repeat the echo, it is the default action of xargs. This one-liner serves as a quick self-contained test, but you can remove the test listener set up before the &

nc -l 7001 & echo  A B C D | xargs -P4 -n1 | nc localhost 7001


amit@deimos:~$ nc -l 7001 & echo A B C D | xargs -P4 -n1 | nc localhost 7001
[6] 7115
[6]   Done                    nc -l 7001
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.