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

Apache POI get line breaks from XWPFRun
Android Display 2 fragments inside another one
Dynamic addition of column in TableView and editing cells using javafx
Java Reflection : invoking inherited methods from child class
If Else Condition not Working in Increase and Decrease Value of qty
For each save (update) hibernate envers creating revisions either changed in table or not
Starting Tomcat with CMD
org.apache.poi.EmptyFileException: The supplied file was empty (zero bytes long)
Assert 2 Lists<String> are equal ignoring order
NoSuchMethodException SoapUI Java
Why can this object access methods of it's parent class?
SQLite database already created and in Android Studio but how do I display information from the database in my application? [duplicate]
Avoid displaying Java Object with description in swagger ui
handling enter key press in editText [duplicate]
MYSQL Date year is saving in other format
Debugging Java classes which are called from Windows batch files

Categories

HOME
ms-access
cakephp
cookies
zeromq
reflection
json.net
grep
routes
google-docs
jira
maven-3
cmd
yarn
leon
sqlite3
disassembler
flyway4
uber-api
node-notifier
maude-system
reveal.js
floating-action-button
circular-dependency
django-admin
angular-ui
propel
lucene.net
custom-wordpress-pages
graphicsmagick
css-animations
jndi
p-value
traffic
publish
bluestacks
repo
subset-sum
gammu
html5-fullscreen
dartium
gesture
vapor
streamreader
trim
elmah
janrain
password-encryption
outlook-api
theming
slickedit
diagnostics
np-complete
flow-control
lync-client-sdk
account-kit
topbeat
specrun
jquery-filter
removechild
file-writing
multiple-regression
holder.js
pagedlist
ubuntu-10.04
bgp
pagerank
revolution-r
ford-fulkerson
hsv
rtbkit
mutation-observers
varargs
cisco-ios
e10s
fscommand
website-monitoring
jsonpickle
camanjs
google-style-guide
codeigniter-routing
asp.net-web-api-odata
reactfx
html5-notifications
runtime.exec
free-variable
e4x
nsnetservice
gdata-api
manchester-syntax
spring-portlet-mvc
eclipse-templates
whoosh
spyware
imac
floating
blitz++
digest-authentication
.nettiers
dentrix
mozilla-prism
fixed-width
simpletest
misv

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App