1

I have this command

curl http://localhost:6800/schedule.json | python -c "import json; print (' '.join(['-d '+key+'='+word for key,word in json.load(open('cron_parameters_testing.json')).items() ] ))"

actually the python command reads parameters from JSON file like this

{ 'project' : 'default' }

and returns the output as -d project=default

I have separately tested python -c "import json; print (' '.join(['-d '+key+'='+word for key,word in json.load(open('cron_parameters_testing.json')).items() ] )) command it works perfectly but it does work with the cURL

my final command that I want to run is

curl http://localhost:6800/schedule.json -d project=default

of course I want -d project=default to be generated from command I mentioned

1 Answer 1

1

| is a pipe, in your case it sends standard output from curl to become the standard input to python. This seems unrelated to your task. Try:

curl http://localhost:6800/schedule.json `python -c "import json; print (' '.join(['-d '+key+'='+word for key,word in json.load(open('cron_parameters_testing.json')).items() ] ))"`

The backticks (`...`) evaluate the command inside and get substituted with the output of the command. Alternatively you can use $(...), especially if you need to nest commands like this.

Sign up to request clarification or add additional context in comments.

3 Comments

in my Ubuntu 14 in VMWare that command works ... but I have a live server with same Ubuntu 14 it does not work ... gives error TypeError: coercing to Unicode: need string or buffer, bool found
@Umair That's purely a python error, thought I can't see what would cause it. What are the outputs of python --version on both machines? Are the JSON files exactly the same? Are there any non-strings in the JSON file(s)?
Yeah, file's content was different

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.