Reputation: 587
I'm a beginner with all this and I need to execute a docker command without using sudo
in ubuntu to use the gcc
compiler.
In order to make that happen, a friend of mine wrote a script, in go lang, named http-to-shell and that is a program that listens as http server on http://localhost:4000
, and executes commands on terminal and returns output to client as a json response.
I run the command
sudo go run http-to-shell.go
and then on another tab i use commands like
curl -d command=ls http://localhost:4000
this works perfectly and then if I use
curl --data-urlencode "[email protected]" http://localhost:4000
it runs the docker command that is in command.txt
and shows the output of the program on the previous tab where i run sudo
go run.
Now, my main issue. Since I'm a beginner I have no idea how to run this from a jsp page from localhost:8080 in ubuntu.
I have been trying, I tried using the answer in Using curl command in java but the process builder doesn't work. I need to run this curl command and get json response to show the user the output of his code.
Please help me out here.
Upvotes: 0
Views: 5322
Reputation: 12491
If you want to use the result of the json in your code then curl is probably not what you want. Curl is however pretty awesome if you want to do stuff from the command line, and yes there are Java curl bindings, but I'd personally use Apache HttpClient
Here is an example using HttpClient to do a REST call. http://www.mkyong.com/webservices/jax-rs/restful-java-client-with-apache-httpclient/
The example uses Spring for the dependencies, I am not sure what your use, so you may have to download the jar yourself and place it on your class path
Upvotes: 1