I have a JAX-WS webservice that receives a string as parameter, calls a Perl script, and returns the string converted to upper case. It is running on Tomcat 8 (localhost on Eclipse).
When I type from the console:
curl -X POST --data "mystring=HelloWorld" http://localhost:8080/MyServices/api/generatePath
Everything works except for the Perl call. On the debugger I see that line is executed, but apparently nothing happens (not even errors). If I run perl /home/me/workspace/match.pl
from the console it works perfectly. The path of the match.pl file is correct.
In addition, process.exitValue()
return 2.
@Path("/")
public class MyServices {
@POST
@Path("/generatePath")
@Produces(MediaType.APPLICATION_JSON)
public Response generatePathService(
@FormParam("mystring") String myString) {
Process process = null;
try {
process = Runtime.getRuntime().exec("perl /home/me/workspace/match.pl --lang en");
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return Response.status(200).entity(myString.toUpperCase()).build();
}
}
I got similar stuff some time ago. The solution for me was to 'accept' the output of the program. Something like this:
You should also try to get the error stream with
p.getErrorStream()
. An alternative could be to change your perl program in that way that there is nothing printed to standard out or error out.Or you call a shell script and redirect the output to dev/null (someting like ´blabla>/dev/null`.