Not able to execute one Java program from another one via. exec()
Hi,
I am new to this forum, so I might be asking a very trivial quetion.
My program Ap1 is :
class Ap1
public static void main(String a[]) throws Exception
Runtime rt=Runtime.getRuntime();
Process p=null;
p=rt.exec("javac,Pr.java");
Runtime.getRuntime().exec("javac,Pr.java");
When I run the above program, I get below error at the line 7(bold one):
D:\batchwe>javac Ap1.java
D:\batchwe>java Ap1
Exception in thread "main" java.io.IOException: CreateProcess: javac,Pr.java err
or=2
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(ProcessImpl.java:81)
at java.lang.ProcessImpl.start(ProcessImpl.java:30)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:451)
at java.lang.Runtime.exec(Runtime.java:591)
at java.lang.Runtime.exec(Runtime.java:429)
at java.lang.Runtime.exec(Runtime.java:326)
at Ap1.main(Ap1.java:7)
Path is set as below(which seems correct):
D:\batchwe>path
PATH=C:\Program Files\Java\jdk1.5.0_05\bin
I am just wondering how to call one Java program from another one?!
Please help.
thanks
Rashmi
Hi diptaPB,
Thanks for your suggestion.
Here is how I tried it again, but not getting the desired output:
Class Pr looks like below -->
class Pr
public static void main(String a[])
System.out.println("hi from process");
When I run 'Pr' from command prompt, i get the desired output:
D:\batchwe>java Pr
hi from process
However, when I call 'Pr' from another program Ap2.java, it seems that it does not call 'Pr':
class Ap2
public static void main(String a[]) throws Exception
Runtime rt=Runtime.getRuntime();
Process p=null;
String[] cmd=new String[2];
cmd[0]="javac";
cmd[1]="Pr.java";
p=rt.exec("cmd");
D:\batchwe>javac Ap2.java
D:\batchwe>java Ap2
************* no output appears here***********************
Looking forward for your help.
regards
Rashmi
Similar Messages
-
Calling one java program from another
Hello,
How can I start another java program from one? Lets
say I want Second.java to start by calling it from
First.java. How do I do it? The two programs are given
below. Any help is appreciated.
Thanks,
Amanda
First.java
import java.io.*;
import java.lang.reflect.*;
public class First
public static void main(String[] args)
Process theProcess=null;
System.out.println("Hello World from First.java!");
String second=new String("Second.java");
//System.load(second);
//Runtime.getRuntime().load(second);
try
theProcess=Runtime.getRuntime().exec( "Second.java"
System.out.println("after exec");
catch (IOException ioe)
System.out.println(">>IOException thrown in
First.java while calling
Second.java."+ioe.getMessage());
Second.java
public class Second
public static void main(String[] args)
System.out.println("Hello World from Second.java!");
}Thanks, warnerja
What if Second.java is on a remote machine i.e.
First.java and second.java are on different machines?
Will I have to use RMI?Well, you'd have to do some kind of remote invocation. Depends on what kinds of apps house the classes. There are all kinds of ways - web services, servlets, RMI, (maybe others...)
That's a totally different question than what you originally posted, and would have been very relevant to say so in the first place. -
Please help with executing a java program from another java program
Hi, I have tried to execute a very simple java program which is printed out "Hello world" from another java gui program when the user click on the "START" button. However, I don't receive any print out on the terminal when they click it. These two programs are being developed in Unix environment. Here is the code that I am trying to use.
Runtime r = Runtime.getRuntime();
r.exec("java HelloWorld");
p.s. HelloWorld is java class of the HelloWorld.javaI think you have to luanch your MS Prompt first before executing the command.
-
Not able to run the Java Program from jre for the ARM processor
Hi ,
I am try to run the jre1.4.2 for the arm core (linux 2.6kernel) which i downloaded from the sun site.
I am created the class file from the J2SE1.4 development kit. I created the simple HelloWorld Program and complied with J2Se then i copied that class file into my IMX board which has ARM core.
When i run the commnd java HelloWorld i am getting this error
dl failure on line 765Error: failed /dev/shm/jvm/j2re1.4.2/lib/arm/client/libjve
Please give me some suggestion to solve this porblem
Thanks in Advance
NarendraI JRE i have download from the sun site . But when i am trying to run the simple helloWorld program in that it is giving the below error.
error:
dl failure on line 765Error: failed /dev/shm/jvm/j2re1.4.2/lib/arm/client/libjvm.so because /dev/shm/jvm/j2re1.4.2/lib/arm/client/libjvm.so: symbol __divdf3, version GCC_3.0 not defined in file libgcc_s.so.1 with link time reference.
Can anybody help me in this how to solve this problem . I also searched in the forum but did not get any answer on that problem
Thanks in advance.
Narendra -
I am not able to run the java Program
Hi All,
I am not able to run a java program... I am able to complie the program sucessfully when i am trying to run it i am getting a error:
Exception in thread "main" java.lang.NoClassFoundError : filename
i have complie and run my programs frequently but now i am not able run my prevoius examples also ...
Can u any body help me out...... I have also update the latest version of JRE but still my problem is not sloved.
Thanks & Regards,
RaviMake sure you take package structure into account.
If you have say
package testing.things;
public class Test
public static void main(String[] args)
System.out.println("World Hello");
}in file Test.java, you compile it with (assuming your current working directory is at the folder in which the source file is located).
javac -d . Test.javaand run it with
java testing.things.TestThe -d . option creates the output at the current directory (with a folder structure matching your package structure).
# -
How to execute a Java program from ODI
Hi All,
I am new to ODI. I would like to know whether its possible to execute a java program from ODI.
Reason for this is, I would like to write information in error tables into a file. And after that another program will mail that error log to concerned person.
Could anyone please help me with this?
Thank you in advance
Regards,
Sriniif you have the java code then u can create a procedure with Java BeanShell as the Technology and write your java code in the procedure
-
I want to be able to execute a swing program from my desktop
i want to be able to execute a swing program from my desktop but i dont know how to go about it. Till now to run the programs i used command prompt. please can you guys help me cross this huddle. I need step by step solution to do this
In Windows, you associate a .jar file with javaw. YOu can do this with a right-click on the system icon, if I recall correctly.
Another option is to wrap the jar file in an executable wrapper so it looks like an .exe. I have used JSmooth to good effect for this.
Good luck. It is only modestly tricky -
Invoke one java application from another?
Hello,
Can anyone tell me how to Invoke one java application from another?
Suppose I have a small java application say, Hello.java which has its own main() method and
I also have another java application, say World.java which has its own main() method too.
What I want to do is invoke or startup World.java from Hello.java.
If possible kindly give code examples?main is just a normal method so Hello can invoke the main method of World just as it would invoke any other method.
Kaj -
Executing a Java Program from within a Java Program
I need to execute the following Java Program from withing another Java Program. The office toolbar command line is
D:\WINDOWS\system32\java.exe -cp E:\Development\Eclipse\UpdateServer\Classes -server -showversion UpdateServer
I can find no combination of ProcessBuilder commands, including those that include "Cmd.exe /c" that will make this program run from within another Java Program. All the examples I can find only show how to run Windows *.exe programs. I keep getting error 123 from ProcessBuilder.start(), but I can find no documentation for error 123.Assuming your code didn't get mangled by the forum
(it's missing one "), it may be that your "-cp
E:\\Develop.." argument is getting quoted as it has a
space in it; try passing "-cp" and "E:\\Develop..."
as two arguments.That worked; specifically the following tested OK:
ProcessBuilder pb = new ProcessBuilder("D:\\WINDOWS\\System32\\Java.exe", "-cp", "E:\\Development\\Eclipse\\UpdateServer\\Classes\\", "-server", "-showversion", "UpdateServer" );
pb.directory(new File("E:\\Development\\Eclipse\\UpdateServer\\Classes\\"));
try{
Process p = pb.start();
InputStream is = p.getErrorStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line;
while ((line = br.readLine()) != null)
System.out.println(line);
p.waitFor();
}catch(IOException ioe){
I was sure I tried that exact same code before, and it did not work, but now it does, at least at the top level (when it is in main of a test program). I will have to wait to try it until later when it is buried deep in a subroutine. -
Execute a java program from an another program
Like we can compile a code from wihin a java file by using the following :
Tool javac = ToolProvider.getSystemJavaCompiler();
Similarly,can we execute i.e. run a java program from within a java file i.e. running d java command from within the java file ??If yes then please tell me how??suppose on the Unix box or from a Unix script ( korn, perl, bourne, bash) you can run the following java program
java ${JAVA_OPTS} -jar ${GMR_APPS_DIR}/risk.jar -I -c ${COB} -r ${BATCH} -o ${XML_DIR}
in java you can do the following :
Runtime rt = Runtime.getRuntime();
try {
Process process = rt.exec("java ${JAVA_OPTS} -jar ${GMR_APPS_DIR}/risk.jar -I -c ${COB} -r ${BATCH} -o ${XML_DIR}
// OR
Process process = rt.exec("/export/apps/Tools/apache-tomcat-5.5.17/bin/startup.sh");
// process.destroy(); if you want to kill the process
process.waitFor();
int RC = process.exitValue();
System.out.println(returnOutput(process.getErrorStream()));
System.out.println(returnOutput(process.getInputStream()));
} catch (Exception ex) {
ex.printStackTrace();
empty the output stream from the script
private String returnOutput(InputStream is) throws Exception {
String s;
StringBuffer strBuff = new StringBuffer();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
while ((s = br.readLine()) != null) {
strBuff.append(s);
return strBuff.toString();
}You need to relace the ${} by the appropriate values.
Regards,
Alan Mehio
London, UK
Edited by: alan_mehio on Jan 16, 2008 4:21 PM -
Calling one report program from another
Hi All,
i am calling one report program from my program & exporting it's output to SAP-SPOOL using SUBMIT statement. I want to fetch the spool no in my program for this spool. Please guide me how this can be achieved? i have tried SYST- SPONO but it's not working.
Thanks & Regards,
Chetan.Hi,
Initially check this it might be helpful to u.
http://help.sap.com/saphelp_sm40/helpdata/en/30/cc154219fce12ce10000000a1550b0/content.htm.
Even use the function module slike Job_open , Job_close this is also one of the methid to achive spool requests.
Regards,
Sana.
Reward with points if found helpful.. -
Compiling one java program by another
hi ppl
how to compile a java program by another java program by using javac command.
that is prog A must compile prog B using " javac B.java" commandTry com.sun.tools.javac.Main.
You require JDK_HOME/lib/tools.jar in CLASSPATH. -
Am not able to run the java program - pls help
1. I installed java in the below path
c:\program files\java\jdk1.5.0
c:\program files\java\jre1.5.0
I set the path in
User variable i. variable name: path
ii. variable value: c:\program files\java\jdk1.5.0\bin
when I compile it in command prompt-applying javac ? it performed successfully-shows
options like ?g create all debug info, -g : new Generate no debug info etc.,
But am not able to run the file. It shows error msg.
2. I specified the same name for file name & class name.
3. Java <class name>
Exception in thread ?main?java.lang.NoclassDeffoundError: <class name>
4. Java ?cp <class name>
Unrecognized option: -cp.<classname>
Could not create the Java Virtual Machine
5. Java ?classpath . <classname>
Exception in thread ?main?.java.lang.unsupported classversionError: <classname>
<unsupported major.minor version 49.0
at java.lang.classloader.defineclass0<native method>
at java.lang.classloader.defineclass<unknown source>
--and many listed below?
6. Java ?classpath c:\program files\java\jdk1.5.0\bin <class name>
Exception in thread ?main?java.lang.NoclassDeffoundError: <class name>
7. I re-installed the java, but still the problem continuing.
pls help... its very urgentIs the java class you compiled/calling in the default package? If it is not, you will have to call it by the fully qualified name.
e.g.
package com.mycompany.myproject;
public class MyClass {
public static void main(String[] args) { }
}This would be called as "Java com.mycompany.myproject.MyClass" and must contain a main method with signature as above.
You would have to call this from folder where the compiled classes are located. If using package, you would call from directory at level of top most package so com folder in this example as Java will look at each package name in qualified name and try to traverse directories with those same names to get to .class file matching class name specified. To avoid this, your newly compiled .class files must also be in your classpath.
Hopefully that helps.
--Kevin -
Executing a JAVA program from a DOS prompt vs the START = RUN dialog
Another novice programmer question...I hope you have the patience...
I have a demo JAVA program that runs fine on my Windows PC when I execute it from a DOS prompt:
K:\COMMON\ITS\STEVEB\java\WhileDemo>java WhileDemo
Count is: 1
Count is: 2
Count is: 3
Count is: 4
Count is: 5
Count is: 6
Count is: 7
Count is: 8
Count is: 9
Count is: 10Can I run this same command from the Windows START => RUN dialog? If I cut an paste the same command, 'K:\COMMON\ITS\STEVEB\java\WhileDemo>java WhileDemo', into the START => RUN dialog I get the following error:
"Windows cannot find 'K:\COMMON\ITS\STEVEB\java\WhileDemo>java WhileDemo'. Make sure you have typed the name correctly, and then try again. To search for a file, click the Start button and then click Search."
Is what I'm attempting to do even possible? Any insights would be greatly appreciated. Thanks.Will a .JAR keep the window from closing on exit? Nope... creating java-archives (jar's) is just the next step down the "how to publish my java application" road. You will eventually (almost certainly) need to progress that far... but there's no rush.
Compiling to and running from class files will do for now.
If you want a command prompt which stays open then open it yourself... Start ~ run: cmd (on NT, XP, Fista)
See also: "cmd here" is one of the windows power toys: http://www.microsoft.com/windowsxp/downloads/powertoys/xppowertoys.mspx -
Not Able to Run A java Program!!!!!!!!!!
Hi Gurus
I have Change my Previos Version of Jdk Now I am getting This Error.
Exception in thread "main" java.lang.UnsupportedClassVersionError: test (Unsuppo
rted major.minor version 49.0)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)Hi Michael
I did the same thing not able to get it.I am using java -version its give me
java version "1.3.1_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1_01)
Java HotSpot(TM) Client VM (build 1.3.1_01, mixed mode)
CLASSPATH=.;C\j2sdk1.4.2_10\lib\rt.jar;C:\apache-ant-1.6.5\lib;C:\apache-ant-1.6.5\lib\ant.jar;C:\jboss-4.0.2\client\jbossall-client.jar;C:\strutsTutorials\jakarta-struts-1.2.4\lib\struts.jar;C:\log4j\logging-log4j-1.2.13\dist\lib\log4j-1.2.13.jar;C:\log4j\logging-log4j-1.2.13\dist\classes;C:\jakarta-tomcat-5.0.28\webapps\validator\WEB-INF\lib\struts.jar;C:\XMLSerilization\xstream-1.1.3.jar
Path=C:\oracle\ora92\bin;C:\Program Files\Oracle\jre\1.3.1\bin;C:\Program Files\Oracle\jre\1.1.8\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\Rational\ClearCase\bin;C:\Program Files\Rational\common;C:\Program Files\lotus\notes\;C:\apache-ant-1.6.5\bin;C:\j2sdk1.4.2_10\bin;
Maybe you are looking for
-
Front end and back end questions
Hi, If I want to develop a web base SOA application by using Jcaps, I have several question want to ask. 1.) In the front end, if i create the page by using eVision to create the page flow and the page layout, how can I match the fields of the page (
-
Trouble downloading apps! Please help :(
I am trying to download apps to my iphone, it keeps telling me that verification is required, when I put in my password, it says "can't verify address", however when I sign in on my computer's itunes it has no problems. HELP please!
-
Can I monitor multiple iPad screens on a single iPad?
I'm a teacher and we have distributed iPads to many of our students recently. We have a few issues with ensuring the pupils are using the iPads as we have asked and are not using it to access social media, games and messaging etc during class time. I
-
Hi, I have a sign being advised Power PC Applications no longer supported when I try to go into Microsoft Word, Excel, Entourage & MSN Messenger, hoe do I resolve this? Any help appreciated Sorry, this is for a Mac Air
-
Return Data from query, but not in datagrid.
Using Flex Builder 2 and ColdFusion, does anyone have advice or examples of running a query to database and returning the results for display in something other than datagrid? I need more control over where my returned data is displaying on my forms.