I'm running this below code in my java class and ideally it should return me a bearer token ....but when I run the code I get Exception.
The below is the code I'm running:
String[] command = {"curl","-v","-
X","POST","https://<Domain name>/oauth2/token","-H","cache-control:
no-cache","-H","content-type: application/x-www-form-urlencoded","-
H","postman-token: a1f5e569-cbc7-63cc-8667-45d85d74784b","-d","client_id=XXXXXXX","&","client_secret=XXXXXXXXXX","&","grant_type=client_credentials"};
for (String s: command)
System.out.print(s);
ProcessBuilder process = new ProcessBuilder(command);
Process p;
try {
p = process.start();
}
The exception I get is
java.io.IOException: Cannot run program "curl": CreateProcess error=2, The system cannot find the file specified
Can someone please let me know what was the issue or how to run the curl command from JAVA.
curlonPATH?new ProcessBuilder("cmd", "/k", "path").redirectOutput(ProcessBuilder.Redirect.INHERIT).start();. This prints out the path in your environment.