Exit status running java classpath in a unix shell script
I'm new to putting java into unix scripts. I have a java classpath running inside of a unix shell script. During my testing it will error with java.io.FileNotFoundException error, which I know why that is, but when I set in my unix shell script this to see the right exit status of success/fail, it always shows a 0 for success when that isn't really the case. Below is the two lines I have set to capture the exit status and just display that exit status for now.
notifycode=$?
echo $notifycode
I have these 2 lines above on a line right below my java command in my unix shell script. How can I get my unix shell script to show the right exit status if the java classpath command fails? Thanks for any help.
That's Java code, it says "End this Java application and send return code 1 back to the shell". As for how the shell gets the return code from the application, that's a question about your shell and not about Java programming, no?
Similar Messages
-
Executing java from unix shell script
Hi, I am trying to execute java program from a unix shell script and the program has a command line parameter. I have tried in ways like
/opt/java1.4/bin/java CollExtractLoadProcess /home/inbox/archive/file_name
/opt/java1.4/bin/java CollExtractLoadProcess "/home/inbox/archive/file_name"
/opt/java1.4/bin/java CollExtractLoadProcess '/home/inbox/archive/file_name'
/opt/java1.4/bin/java CollExtractLoadProcess file_name
No matter how I execute it gives me the following error
Exception in thread "main" java.lang.ClassFormatError: CollExtractLoadProcess (C
ode segment has wrong length)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:537)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:12
3)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:251)
at java.net.URLClassLoader.access$100(URLClassLoader.java:55)
at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
Could someone please let me know what is the correct way of doing this?
Thanks.Sounds like you either have a corrupt class file or you're using an older version of the JVM to try to execute classe that were compiled for a newer version.
-
R/3 to other oracle system Unix Shell scripts Execute
Hi,
Here SAP 4.7 version, is it any possibility to run/execute other oracle system Unix shell scripts from sap program?
With Regards,
Anil...yes,
1.define own external command (sm69)
2. run this command from your ABAP code by callig function module SXPG_COMMAND_EXECUTE
regards,darek -
Running Unix Shell scripts through Java
How to run Unix shell scripts through Java program ?
Use:
Process p = Runtime.getRuntime().exec("sh script.sh");Then you can use:
p.getOutputStream and read the output of your program. -
Running UNIX shell scripts from a Java app
I want to build a GUI in Java as a front-end to a collection of UNIX shell scripts I have written. Is this possible?
It is possible, but it kinda defeats the purpose of shell scripts no?
-
Error while executing unix shell script from java program
Hi All,
I am trying to execute unix shell script from a java program using Runtime.execute() method by passing script name and additional arguments.
Code snippet :
Java Class :
try{
String fileName ="test.ksh";
String argValue ="satish"; // value passed to the script
String exeParam = "/usr/bin/ksh "+fileName+" "+argValue;
Process proc = Runtime.getRuntime().exec(exeParam);
int exitValue = proc.waitFor();
sop("Exit Value is : "+exitValue);
catch(Exception e)
e.printStackTrace();
}Test.ksh
export -- application realated paths..
nohup abc.exe 1> test.log 2>&1;
$1
exit.By running the above java class , i am getting exit Value: 139 and log file test.log of 0 bytes.
when i am running the same command (/usr/bin/ksh test.ksh satish) manually, it's calling abc.exe file successfully
and able generate the logs properly.
Pls let us know where exactly i am stuck..
Thanks in advance,
Regards,
SatishHi Sabre,
As per the guidelines provided by the article, i had done below changes..
InputStream is = null;
InputStreamReader iStreamReader = null;
BufferedReader bReader = null;
String line = null;
try{
String fileName ="test.ksh";
String argValue ="satish"; // value passed to the script
String exeParam = "/usr/bin/ksh "+fileName+" "+argValue;
Process proc = Runtime.getRuntime().exec(exeParam);
is = proc.getErrorStream();
iStreamReader = new InputStreamReader(is);
bReader = new BufferedReader(iStreamReader);
System.out.println("<ERROR>");
while((line = bReader.readLine()) != null)
System.out.println("Error is : "+line);
System.out.println("</ERROR>");
int exitValue = proc.waitFor();
sop("Exit Value is : "+exitValue);
catch(Exception e)
e.printStackTrace();
Now , it's showing something like..
<ERROR>
</ERROR> -
Java exec() of UNIX shell script
I have a java application that uses:
p = Runtime.getRuntime().exec( cmdLine);
to execute a UNIX shell script, for example:
#!/bin/ksh
. /export/pc112477/freeware/work1/wsEnv
export PATH=/opt/sfw/bin:/usr/ccs/bin:/usr/bin:/usr/ucb:$PATH
cd /export/pc112477/freeware/work1/usr/src/pkgdefs/SFWnmap
/usr/ccs/bin/make -e ROOT=$ROOT install
RESULT=$?
if [ $RESULT = 0 ]
then
echo "Package source"
cd /export/pc112477/freeware/work1/usr/src/pkgdefs/SFWnmapS
/usr/ccs/bin/make -e ROOT=$ROOT install
RESULT=$?
fi
exit $RESULT
Some times the running of the script locks up depending on how much work the script has to, eg. if the make calls pkgmk for a small package it runs okay but if its a large package it locks up in pkgmk.
The script itself works okay if run directly
Does anyone have any ideas on why this locks up and how I could stop it doing it.
ThanksFor anyone who stumbles across this and needs an answer:
To empty the standard error and output, you need to use getErrorStream() and getInputStream() on the Process object created when you execed your command. Create new InputStreamReaders with the streams from the process, then wrap those with BufferedReaders and read each line with a while loop. This is the basic thing you need to do:
try{
Process proc = Runtime.getRuntime().exec(command);
InputStreamReader isr = new InputStreamReader(proc.getErrorStream());
BufferedReader errReader = new BufferedReader(isr);
String line;
while((line = errReader.readLine()) != null)
<do something with each line of error>
} //end try
catch(<errors>) {
<do something with errors>
} //end catch
What you really should do is put the stream handling in a separate class that extends Thread, create an instance for the error and output streams, and start each one. There is a class called StreamGobbler that does this sort of thing. Look at http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html to find out more about it and read a detailed explanation of different problems with exec(). -
Error while trying to execute a unix shell script from java program
Hi
I have written a program to execute a unix shell script in a remote machine. I am using J2ssh libraries to estabilish the session connection with the remote box.The program is successfully able to connect and authenticate with the box.
The runtime .exec() is been implemented to execute the shell script.I have given below the code snippet.
try {
File file_location = new File("/usr/bin/");
String file_location1 = "/opt/app/Hyperion/scripts/daily";
String a_mib_name = "test.sh";
String cmd[] = new String[] {"/usr/bin/bash", file_location1, a_mib_name};
Runtime rtime = Runtime.getRuntime();
Process p = rtime.exec(cmd, null, file_location);
System.out.println( "Connected to the server1" );
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = br.readLine();
while(line !=null)
System.out.println(line);
line = br.readLine();
br.close();
p.getErrorStream ().close ();
p.getOutputStream().close();
int retVal = p.waitFor();
System.out.println("wait " + retVal);
//session.executeCommand("ls");
catch (IOException ex) {
I get an error message
Connected to the server
java.io.IOException: Cannot run program "/usr/bin/bash" (in directory "\usr\bin"
): CreateProcess error=3, The system cannot find the path specified
at java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at SftpConnect.main(SftpConnect.java:143)
Caused by: java.io.IOException: CreateProcess error=3, The system cannot find th
e path specified
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
I am sure of the file path where the bash.sh and test.sh are located.
Am i missing something? Any help would be greatly appreciated.
Thanks
SenthilHi, I am using a simple program to connect to a RMI server and execute shell script. I use the Runtime.exec aommand to do the same.
The script is sh /tmp/pub/alka/test.sh /tmp/pub/alka/abc/xyz/ul ul
The script when run from the server, gives no errors. But when ran using rthe above method in java, gives errors as follows,
Mycode:
String command = "/bin/sh /tmp/pub/alka/test.sh /tmp/pub/alka/abc/xyz/ul ul";
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec(command);
int exitVal = proc.exitValue();
System.out.println("Process exitValue: " + exitVal);
java.io.IOException: CreateProcess: /bin/sh /tmp/pub/alka/test.sh /tmp/pub/alka/abc/xyz/ul ul error=3
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
at java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at DecryptTest.main(DecryptTest.java:18)
Can anyone please help -
Run Unix command / Run Unix shell script from Forms9i
Hi,
I have a requirement to run Unix command and Unix shell scripts from Forms9i.
I know HOST command cannot be used directly. I also know we can create some JAVA stored procedure to perform the task, but I don't want to create any JAVA stored procedure as there are some security concerns.
Please point me towards any other way to achieve the same.
I would really appreciate your help.
Thanks,
KumarThere is no reason why HOST can't be used. This is what it is for. As for using Java, it is not a stored procedure that you would be using, it would be imported Java (imported into the form).
The best way to use the HOST command is to call a script (.sh) rather than calling a Unix command directly. This is because HOST will not pick up environment variables set at the system level. So the script would first need to set the necessary environment variables then call the desired commands. -
Unix shell script run from pl/sql procedure
Hi Guru
I want to run unix shell script from pl/sql procedure. Actual I want to run it from developer 10g form.
Please guide me in this regards
Regards
JewelLook at the host or client_host builtins in the help
-
How to execute unix shell script from Java ...
Hi,
Anyone know how to execute unix shell script from Java?
Suppose I have several shell scripts written in perl or tcl or bash.
I just want to catch the output of that script.
Is there any ready to use module/object for this?
Please let me know, this is quite urgent for my study assigment.
Thanks in advance,
Regards,
meLook up Runtime.exec()
-
how to run 3 job(a,b,c) parallel in unix shells script and after will complete d will start and we have to handle the error also
032ee1bf-8007-4d76-930e-f77ec0dc7e54 wrote:
how to run 3 job(a,b,c) parallel in unix shells script and after will complete d will start and we have to handle the error also
Please don't overwhelm us with so many details!
Just off the top of my head ... as a general approach ... something like
nohup proca
nohup procb
nohup procc
while (some condition checking that all three procs are still running ... maybe a ps -ef |grep )
do
sleep 2
done
procd
But, we'd really need to know what it is you are really trying to accomplish, instead of your pre-conceived solution. -
Invoking unix shell scripts from java?
Hi,
could someone explain to me how one wuld invoke unix shell scripts from java.
Also, could you invoke Visual Basic scripts from java.
Finally, could you do this from an EJB?
thanks for any help....
suduI just posted a snippet of this solution in the topic about widows commands chech it out it works just fine for unix shell scripts.
--Ian -
Running SQLPLUS from UNIX shell script
I'm not sure if this is the right forum, but...
How can I execute a sql file from inside the UNIX shell script, logging on to Oracle w/o supplying a UID/pwd? Normally, we log into UNIX using our own logon, then sudo as another user to login to Oracle. Now, I'm trying to create a UNIX shell script, where I'm already sudo'd as the UserID that logs into Oracle. I've tried the following, but can't get it to work. I'm a UNIX scripting noob. Any ideas?
example:
#! /usr/bin/ksh
sqlplus / \@test.sql << EOF
exit;
EOFI'm a UNIX scripting noob.In which case I feel obligated to point you at William Robertson's excellent article Database Shellscripts Considered Harmful. Save yourself a world of pain.
Cheers, APC -
Unable to pass parameter in oracle procedure through unix shell script
Hi Experts,
I have oracle procedure where in I have to pass the value of procedure parameter through unix script.
Follwoing is the sample procedure which i tried to exceute from the unix.
Procedure:
create or replace procedure OWNER.PRC_TESTING_OWNER(OWNER IN VARCHAR2) AS
sql_stmt varchar2(1000) := NULL;
v_count number := 0;
v_owner varchar2(100) := owner;
begin
sql_stmt:='select count(1) from '||v_owner||'.EMP@infodb where rownum<=10';
execute immediate sql_stmt into v_count;
DBMS_OUTPUT.PUT_LINE(sql_stmt);
DBMS_OUTPUT.PUT_LINE(v_count);
END;The script which I used is:
Unix
#!/bin/ksh
parm=$1
echo start
sqlplus -s scott@DEV/tiger <<EOF >>result_1.txt
set serveroutput on;
select '$parm' from dual;
exec owner.PRC_TESTING_OWNER('$parm');
EOFThe script is working fine that is i am able to pass to parameter value through unix shell script. :)
But if I want to pass the value of the owner in cursor , I am unable to pass this value through unix.
Following the procedure which i am trying to implement.
create or replace procedure OWNER.PRC_TESTING_OWNER(OWNER IN VARCHAR2) IS
v_owner varchar2(100) := owner;
CURSOR main_cur IS
select
i.ROWID rid ,
emp_name,
deptid
from v_owner.employee;
CURSOR subset_cur(c_deptid NUMBER ) IS
SELECT *
FROM v_owner.DEPT d
where d.dept_id=c_deptid;
--##main loop
FOR i IN main_cur LOOP
FOR j IN subset_cur(i.deptid) LOOP
BEGIN
insert into v_owner.RESULT_TABLE
END;
END LOOP;
END LOOP;How can i pass parameter value of the stored procedure through unix script(that is "owner" in this case), when these parameter value is
used in cursor? :(
Can anybody help me regarding the same?
Thanks in Advance !! :DIt's not the parameter in the cursor that is the problem, it's that you are trying to use static SQL for something that won't be known until run time (the owner of the table).
You would need to use something like ...
declare
l_owner varchar2(30) := 'SCOTT';
l_ref_cursor sys_refcursor;
type l_ename_tab is table of scott.emp.ename%type;
l_ename_array l_ename_tab;
begin
open l_ref_cursor for
'select ename
from ' || l_owner || '.emp';
loop
fetch l_ref_cursor bulk collect into l_ename_array limit 10;
exit when l_ename_array.COUNT = 0;
for x in 1 .. l_ename_array.count
loop
dbms_output.put_line(l_ename_array(x));
end loop;
end loop;
close l_ref_cursor;
end;
SMITH
ALLEN
WARD
JONES
MARTIN
BLAKE
CLARK
SCOTT
KING
TURNER
ADAMS
JAMES
FORD
MILLER
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.01
Maybe you are looking for
-
Every once in a while my macbook pro just randomly instantaneously freezes and the screen turns gray and it has only done it while connected to a high res 22'' Dell external monitor (so far). Usually when this happens I'm listening to music and I not
-
Help, all flash videos are cropping randomly. Also, when I go full screen, the video doesn't fill up the entire screen like it used to. I still see black frame on all sides. It only happens on Firefox. I tried uninstalling both flash and firefox then
-
Need Windows 7 and Outlook 2010 Sync help
I am attempting to HotSync my calendar from Outlook 2010 onto my Centro and I am not successful. What am I missing???? I have Desktop Manager V.6.2.2, Hotsync Manager v. 7.0.2, Palm Garnet OS v.5.4.9 and each time I connect I get a message that hots
-
Powerbook AC/battery issue
Hi there wondered if anyone could give advice to this issue. I recently acquired a used Powerbook G4 Aluminum 15" widescreen which I bought knowing it had a dead battery which I'm due to replace, however as I have to leave it plugged in with the ac a
-
Compare SQL file tables as a file content VS Documentum or Alfresco
Hello - Documentum & Alfresco are 2 examples of Document Content Management (file repository, workflows, notifications, etc), I am interesting in the file content management where system provides file repository and some extra features like check in