servlets - ProcessBuilder.start() returns 0 but doesn't execute shell script -


i'm trying use processbuilder execute shell script on linux server, servlet running on websphere application server.

the code returns 0 (using .waitfor()), script doesn't appear execute. if put invalid path script "file not found" exception, know it's finding script...but doesn't appear execute.

the script calls script should output zip file (i've got 'touch' line see if anything's happening in there...but nothing doing).

the script runs fine command line, using same command i'm passing .start().

here's snippet servlet:

protected void dopost(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception {      system.out.println("in dopost");       system.out.println("about kick off processbuilder");     processbuilder pb = new processbuilder("/opt/ibm/websphere/appserver/profiles/appsrv01/installedapps/localhostnode01cell/svc_war.ear/svc.war/test.sh");     pb.redirecterrorstream(true);     process process = pb.start();     bufferedreader br = new bufferedreader(new inputstreamreader(process.getinputstream()));     int ch;     while ((ch = br.read()) != -1)         system.out.println((char)ch);     br.close();     try {         int exitval = process.waitfor();         system.out.println("exit value: " + exitval);     } catch (interruptedexception e) {         e.printstacktrace();     } 

the .redirecterrorstream() , .getinputstream() see if might hitting buffer issues i've read others refer (although wouldn't expect .waitfor() return 0 if case).

this first foray processbuilder, i'm hoping i'm missing obvious.

any ideas/hints appreciated.

oh yeah...here's output get:

[4/5/13 21:32:41:791 pdt] 0000004d systemout     o in dopost [4/5/13 21:32:41:791 pdt] 0000004d systemout     o kick off processbuilder [4/5/13 21:32:41:818 pdt] 0000004d systemout     o exit value: 0 

thanks.

got working....i needed set working directory using:

pb.directory(new file("/opt/ibm/websphere/appserver/profiles/appsrv01/installedapps/localhostnode01cell/svc_war.ear/svc.war/")); 

so final solution looks like:

protected void dopost(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception {  system.out.println("in dopost");   system.out.println("about kick off processbuilder"); processbuilder pb = new processbuilder("/opt/ibm/websphere/appserver/profiles/appsrv01/installedapps/localhostnode01cell/svc_war.ear/svc.war/test.sh"); pb.redirecterrorstream(true); pb.directory(new file("/opt/ibm/websphere/appserver/profiles/appsrv01/installedapps/localhostnode01cell/svc_war.ear/svc.war/")); process process = pb.start(); bufferedreader br = new bufferedreader(new inputstreamreader(process.getinputstream())); int ch; while ((ch = br.read()) != -1)     system.out.println((char)ch); br.close(); try {     int exitval = process.waitfor();     system.out.println("exit value: " + exitval); } catch (interruptedexception e) {     e.printstacktrace(); } 

Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -