Skip to main content
2 of 2
deleted 232 characters in body
Rui F Ribeiro
  • 58k
  • 28
  • 156
  • 239

Converting stdout to raw-data not accepting multiple words using xargs and piping

I am currently running the command: echo "hello world" | xargs curl http://localhost:8080/function/func_wordcount -d" which takes the stdout of echo "hello world" and then pipes it to func_wordcount using the -d option. The -d option is for sending raw data and my func_wordcount takes the raw data input and prints the number of words and the number of letters.

For example, when I write echo "hello" | xargs curl http://localhost:8080/function/func_wordcount -d" the output is: 1, 5 meaning that there was one word which contained 5 letters.

However, when I try to include many words I get an error. When I write echo "hello world" | xargs curl http://localhost:8080/function/func_wordcount -d" I get the output 1, 5, then a newline with the error: curl: (6) could not resolve host: world. So I am pretty sure that it is splitting hello world into two words when I convert the stdout to raw data using the -d option.

Also, just to show that the function works without piping and converting, when I run my function with just curl http://localhost:8080/function/func_wordcount -d "hello world" I get 2, 11 showing that there are two words and 11 characters.

My question is how to work around this splitting issue. The part that I find confusing is why it is parsing just the first half of the input and completing that, and then throwing an error on the second part instead of just sending one chunk of data. I have only been able to send input that is not delimited at all by spaces so the functions uses become very limited.

cjnash
  • 123
  • 4