java
getting error from java
How can I call a shell script through java code? I have writtent the below code. I am getting the process exit code as 127. But it seems my shell script in unix machine is never called. String scriptName = "/xyz/downloads/Report/Mail.sh"; String[] commands = {scriptName,emailid,subject,body}; Runtime rt = Runtime.getRuntime(); Process process = null; try{ process = rt.exec(commands); process.waitFor(); int x = process.exitValue(); System.out.println("exitCode "+x); }catch(Exception e){ e.printStackTrace(); }
From this post here 127 Return code from $? You get the error code if a command is not found within the PATH or the script has no +x mode. You can have the code below to print out the exact output BufferedReader stdInput = new BufferedReader(new InputStreamReader(process.getInputStream())); String s= null; while ((s = stdInput.readLine()) != null) { System.out.println(s); } BufferedReader stdOut = new BufferedReader(new InputStreamReader(process. getErrorStream())); String s= null; while ((s = stdOut.readLine()) != null) { System.out.println(s); }
Related Links
Stuck up in creation of file in webcontent folder in dynamic web project
Redisplaying JSP after post to Servlet
PersistenceUnit: jpaData - Unable to build EntityManagerFactory
Java Standalone Program to JSP communication
Log4j2: How to write logs to separate files for each user?
How to generate TimeUUID in Java/Scala
Formatting and validating a date in JSF
How to make runnable Jar programs that do not fail silently?
Is it possible to send broadcast socket in jsp?
Passive FTP with Appengine
Findbug immutable date fixes do not work
make grid view with java graphics
Throws Exception Error in Java
Get all classes from a Jar file using Reflection
How to make java message dialog bigger?
Select One menu is not setting the selected value to backend