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

Categories

HOME
cloud
wso2
hook
proxy
cookies
oracle11g
fluentd
grep
objectgears
rsync
sqlite-net-extensions
amazon-ecs
jxls
paradox
cloudkit
facebook-php-sdk
here-api
fancybox-3
spring-kafka
dynamics-crm-online
libtiff
facebook-page
solaris-10
reactive-cocoa
connection-string
karma-jasmine
custom-wordpress-pages
realex-payments-api
centos6.5
chromebook
wpfdatagrid
publish
tinymce-4
fog
textmate
space-complexity
theano.scan
graphenedb
firebase-admin
unixodbc
businessworks
btrace
apple-news
auto-update
dds
boost-multi-index
winscp-net
dropbox-php
aurelia-validation
libusb-win32
np-complete
ifs
sqlbulkcopy
yt-project
nxt
vmware-tools
mathematica-frontend
etsy
connect-by
flash-cs5
pagedlist
pagerank
ptrace
wso2cloud
ruby-2.2
content-length
deis
mono-embedding
generic-programming
cisco-ios
umbraco6
python-green
gwidgets
dealloc
hyprlinkr
resty-gwt
message-driven-bean
centos5
xsockets.net
dir
apc
ruby-datamapper
ril
mqx
specification-pattern
angularjs-controller
unc
frameset
datawindow
spring-portlet-mvc
pendrive
hgsubversion
subscript
fireworks
gwt-ext
data-loss
ecl
winbugs14
gdlib
nsviewanimation
yagni
zend-decorators
multiple-languages
document-conversion

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