Question

I want to call a bash script from GWT server

I coded up my first application with GWT/RPC, and I need to call a bash script on the server side (from MyOwnServiceImpl extends RemoteServiceServlet implements MyOwnService).

ProcessBuilder doesn't work

To do that, I confess that I am using java.lang.ProcessBuilder, which is apparently "not supported by GAE" (I just ignored the warning). As it is running on the server side, it seemed to me that it should work anyways. I feel that I am missing something.

Something seems to be preventing the call from being executed, even though the required packages are correctly imported, the binaries are found, the execution doesn't crash. But the call is just not successful (for example even mkdir is not executed on the server).

Related posts weren't much help...

How to execute a Unix shell script via GWT? (does not give a complete answer, and I could not simply comment on the answer) GWT + ProcessBuilder (mentions precisely the solution I implemented which is not working for me, see above)

Any thoughts on this would be much appreciated, thanks!

Was it helpful?

Solution

In a GWT application without GAE you can use Runtime.getRuntime().exec("some command"); If you want to read out the result of the command, you can use:

Process p = Runtime.getRuntime().exec("A command");
BufferedReader in = new BufferedReader(new InputStreamReader(p.getErrorStream()));
StringBuilder builder = new StringBuilder();
String line = null;
 while ((line = in.readLine()) != null) {
     builder.append(line + "\n");
 } 
String result = builder.toString();

If the command above should not work, i guess you have to remove GAE from your project to run a bash script.

OTHER TIPS

  1. you can call bash script with GWT,if your servet side on your computer.
  2. the limit is GAE for secury. no way to cross this limit.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top