Help! how to run other programs using java
how can i run other programs or exe files using java, anyone can give sample codes for this.
ex. if I click [run MsWord] button, then msWord automatically lunch
RunTime.getRuntime().exec(string command)
I guess, it might help you..java.lang.Runtime
Similar Messages
-
How can I run other programs using java program
hi experts,
I am trying to execute a set of commands from java program
eg: from command prompt
java CommandExecutor c:\winnt\notepad.exe c:\some.exe c:\onemorecommand.exe
and inside the CommandExecutor main method..
public static void main(String []arg)
for(i = 0; i < arg.length; i++)
Runtime.getRuntime().exec(arg(i));
the above code is executing all the command one after the other, but I want to execute the above commands squentially, i.e I want to execute the second command only after finishing the first command and the third after finishing the second and so on depending upon the arguments passed, how can I acheive this...
I have tried to use the Process which is returned by the exec(arg) method but the exitValue() returns same value before execution and after execution.
thanks,
krishnaDid you try to get the process returned and then try
process.waitFor() method. This waits for the process to finish.
After that try the next execution -
How to run native program with Java program?
Hello
I've got following problem. I'd like to write file browser which would work for Linux and
Windows. Most of this program would be independent of the system but running programs not. How to run Linux program from Java program (or applet) and how to do it in Windows?.
CheersTry this:
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec("ls -l");
InputStream stream = proc.getInputStream();
InputStreamReader isr = new InputStreamReader(stream);
BufferedReader br = new BufferedReader(isr);
String line = null;
while ( (line = br.readLine()) != null) .....
"if the program you launch produces output or expects input, ensure that you process the input and output streams" (http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html) -
How to run the program using specific classpath
Recently I installed Javamail 1.2 and JAF1.0.1 on my NT Box and set up the classpath. I can compile my java email code by using: javac myEmail.java. But when I tried to run the code using java myEmail, it always gives the error: Exception in thread "main" java.lang.NoClassDefFoundError: myEmail.
when I use -verbose and found that it always goes to:
C:\Program Files\JavaSoft\JRE\1.3.1\lib\rt.jar to find classes even I use -cp option to point Javamail\mail.jar and activation.jar.
what is wrong with it? Thank you in advance!!!!!!What does this have to do with JMS. I suggest that this should have been posted to the Java Programming forum where you would have gotten a quick response as this is a simple problem to diagnose.
The problem is that the class myEmail, which you created, is not on the class path so it cannot find it. It has nothing to do with the location of mail.jar and activation.jar, although this may cause problems later.
What you need to do is check the classpath in the environment variables section of the System dialog box. Make sure it refers to . (the current directory) as well as the locations of mail.jar and activation.jar. Also when you invoke myEmail ensure you are in the same directory.
Hope this helps -
Running external program using java
hi
i am trying to run an external program using the runtime.exec() method. my problem is that the external program only runs when i press ctrl-c to exit my program. does anyone know how i can execute the external program while my program is still running without having to quit the program?should i be using threads?
thanksAs per the api doc exec will be executed as a seperate process
Process exec(String command) ------Executes the specified string command in a separate process.
Can you able to share that code what you have written ? -
How to run Other application from Java
I want to run other applications such as IE.exe, notepad.exe from Java? How can I run?
Dear Friend, the following is the code to open IExplorer from Java Program
class RunTimeTest {
public static void main(String args[]) {
try {
Runtime.getRuntime().exec("C:\\Program Files\\Internet Explorer\\IEXPLORE.exe");
catch(Exception e) {
[\code]
ALL THE BEST
Shiva -
How to run a program in java by double clicking on it?
hi,
simple question for you all:
normally when i do java programs i am used to compiling it and running it via JBuilder.
However, i saw a java program that had been installed on a desktop and the user double clicked it and it came straight up.
how can this be done?You can create executable jar files that can start up an application when double clicked. If you want more specifics, search the forums for "executable jar" and I'm sure you'll get more than enough info.
-
How to run windows program through java applications.
pls help me!!!!! code RED!~
C:\Documents and Settings\student\Desktop\Running.java:12: cannot resolve symbol
symbol : variable JMStudio
location: class Running
String path="C:/Program Files/MF2.1.1/bin"+JMStudio;
^
1 error
this error is generated
any idea on how to solve it? -
How to call other program in java
how do i write code to call a program, software in window envirenment?
such as opening Microsoft Excel files using Microsoft excel?
plz helppublic static void main(String[] args)
try
Runtime.getRuntime().exec("Book1.xls");
catch (IOException ed)
}i tried, but it not working , plz help -
How to run batch programs using SUBMIT command without any interaction need
Hello ABAP gurus,
I have created a batch program in SE38 which calls many other SE38 Programs (Reports).
I have used the command SUBMIT to call the sub programs. There are about 15 sub programs that this main batch program is calling.
It works fine, but after calling each subprogram it stops and I have to manually click on 'Back Button' in green on the sap screen to run the next program in the list. Like this I have to do 15 times to run all the programs in the batch.
Is there a way to avoid this manual intervention and make the program run all the sub programs on its own.
Your feedback will be highly appreciated.
Thanks
RamThanks Sampath for the response.
Yes I am using the option "AND RETURN". So it is coming out of each sub program, and it is at this stage it waits for me to click on 'backward green arrow' to continue to the next.
Here is the code I have used
SUBMIT Z_AS_BI_F0005_EXTRACT WITH S_DATE IN S_DATE WITH P_TEST = 'N' AND RETURN.
SUBMIT Z_AS_BI_DIVISION_EXTRACT WITH S_DATE IN S_DATE WITH P_TEST = 'N' AND RETURN.
SUBMIT Z_AS_BI_COMPANY_EXTRACT WITH S_DATE IN S_DATE WITH P_TEST = 'N' AND RETURN.
SUBMIT Z_AS_BI_CUSTOMER_EXTRACT WITH S_DATE IN S_DATE WITH P_TEST = 'N' AND RETURN.
SUBMIT Z_AS_BI_BRANCH_EXTRACT WITH S_DATE IN S_DATE WITH P_TEST = 'N' AND RETURN.
SUBMIT Z_AS_BI_BUS_UNIT_EXTRACT WITH S_DATE IN S_DATE WITH P_TEST = 'N' AND RETURN.
SUBMIT Z_AS_BI_ADDRESS_EXTRACT WITH S_DATE IN S_DATE WITH P_TEST = 'N' AND RETURN.
SUBMIT Z_AS_BI_CUSTOMER_GROUP_EXTRACT WITH S_DATE IN S_DATE WITH P_TEST = 'N' AND RETURN.
SUBMIT Z_AS_BI_GROUP_EXTRACT WITH S_DATE IN S_DATE WITH P_TEST = 'N' AND RETURN.
SUBMIT Z_AS_BI_PMT_TERMS_EXTRACT WITH S_DATE IN S_DATE WITH P_TEST = 'N' AND RETURN.
SUBMIT Z_AS_BI_REGION_EXTRACT WITH S_DATE IN S_DATE WITH P_TEST = 'N' AND RETURN.
SUBMIT Z_AS_BI_TERRITORY_EXTRACT WITH S_DATE IN S_DATE WITH P_TEST = 'N' AND RETURN.
Any other suggestions or feedback will be appreciated.
Tks
Ram -
How to send mail attachments using java mail
can any one help how to create mails attachments using java mail
you can do it like this:
Message msg = new MimeMessage(session);
String fileAttachment = "c:/test.txt";
Multipart mp = new MimeMultipart();
BodyPart bp = new MimeBodyPart();
FileDataSource fds = new FileDataSource(fileAttachment);
bp.setDataHandler(new DataHandler(fds));
bp.setFileName(fds.getName());
mp.addBodyPart(bp);
msg.setContent(mp);
... -
How to set proxy authentication using java properties at run time
Hi All,
How to set proxy authentication using java properties on the command line, or in Netbeans (Project => Properties
=> Run => Arguments). Below is a simple URL data extract program which works in absence of firewall:
import java.io.*;
import java.net.*;
public class DnldURLWithoutUsingProxy {
public static void main (String[] args) {
URL u;
InputStream is = null;
DataInputStream dis;
String s;
try {
u = new URL("http://www.yahoo.com.au/index.html");
is = u.openStream(); // throws an IOException
dis = new DataInputStream(new BufferedInputStream(is));
BufferedReader br = new BufferedReader(new InputStreamReader(dis));
String strLine;
//Read File Line By Line
while ((strLine = br.readLine()) != null) {
// Print the content on the console
System.out.println (strLine);
//Close the input stream
dis.close();
} catch (MalformedURLException mue) {
System.out.println("Ouch - a MalformedURLException happened.");
mue.printStackTrace();
System.exit(1);
} catch (IOException ioe) {
System.out.println("Oops- an IOException happened.");
ioe.printStackTrace();
System.exit(1);
} finally {
try {
is.close();
} catch (IOException ioe) {
}However, it generated the following message when run behind the firewall:
cd C:\Documents and Settings\abc\DnldURL\build\classes
java -cp . DnldURLWithoutUsingProxy
Oops- an IOException happened.
java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158)
at java.net.Socket.connect(Socket.java:452)
at java.net.Socket.connect(Socket.java:402)
at sun.net.NetworkClient.doConnect(NetworkClient.java:139)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:402)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:618)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:306)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:267)
at sun.net.www.http.HttpClient.New(HttpClient.java:339)
at sun.net.www.http.HttpClient.New(HttpClient.java:320)
at sun.net.www.http.HttpClient.New(HttpClient.java:315)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:510)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:487)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:615) at java.net.URL.openStream(URL.java:913) at DnldURLWithoutUsingProxy.main(DnldURLWithoutUsingProxy.java:17)
I have also tried the command without much luck either:
java -cp . -Dhttp.proxyHost=wwwproxy -Dhttp.proxyPort=80 DnldURLWithoutUsingProxy
Oops- an IOException happened.
java.io.IOException: Server returned HTTP response code: 407 for URL: http://www.yahoo.com.au/index.html
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1245) at java.net.URL.openStream(URL.java:1009) at DnldURLWithoutUsingProxy.main(DnldURLWithoutUsingProxy.java:17)
All outgoing traffic needs to use the proxy wwwproxy (alias to http://proxypac/proxy.pac) on port 80, where it will prompt for valid authentication before allowing to get through.
There is no problem pinging www.yahoo.com from this system.
I am running jdk1.6.0_03, Netbeans 6.0 on Windows XP platform.
I have tried Greg Sporar's Blog on setting the JVM option in Sun Java System Application Server (GlassFish) and
Java Control Panel - Use browser settings without success.
Thanks,
GeorgeHi All,
How to set proxy authentication using java properties on the command line, or in Netbeans (Project => Properties
=> Run => Arguments). Below is a simple URL data extract program which works in absence of firewall:
import java.io.*;
import java.net.*;
public class DnldURLWithoutUsingProxy {
public static void main (String[] args) {
URL u;
InputStream is = null;
DataInputStream dis;
String s;
try {
u = new URL("http://www.yahoo.com.au/index.html");
is = u.openStream(); // throws an IOException
dis = new DataInputStream(new BufferedInputStream(is));
BufferedReader br = new BufferedReader(new InputStreamReader(dis));
String strLine;
//Read File Line By Line
while ((strLine = br.readLine()) != null) {
// Print the content on the console
System.out.println (strLine);
//Close the input stream
dis.close();
} catch (MalformedURLException mue) {
System.out.println("Ouch - a MalformedURLException happened.");
mue.printStackTrace();
System.exit(1);
} catch (IOException ioe) {
System.out.println("Oops- an IOException happened.");
ioe.printStackTrace();
System.exit(1);
} finally {
try {
is.close();
} catch (IOException ioe) {
}However, it generated the following message when run behind the firewall:
cd C:\Documents and Settings\abc\DnldURL\build\classes
java -cp . DnldURLWithoutUsingProxy
Oops- an IOException happened.
java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158)
at java.net.Socket.connect(Socket.java:452)
at java.net.Socket.connect(Socket.java:402)
at sun.net.NetworkClient.doConnect(NetworkClient.java:139)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:402)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:618)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:306)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:267)
at sun.net.www.http.HttpClient.New(HttpClient.java:339)
at sun.net.www.http.HttpClient.New(HttpClient.java:320)
at sun.net.www.http.HttpClient.New(HttpClient.java:315)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:510)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:487)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:615) at java.net.URL.openStream(URL.java:913) at DnldURLWithoutUsingProxy.main(DnldURLWithoutUsingProxy.java:17)
I have also tried the command without much luck either:
java -cp . -Dhttp.proxyHost=wwwproxy -Dhttp.proxyPort=80 DnldURLWithoutUsingProxy
Oops- an IOException happened.
java.io.IOException: Server returned HTTP response code: 407 for URL: http://www.yahoo.com.au/index.html
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1245) at java.net.URL.openStream(URL.java:1009) at DnldURLWithoutUsingProxy.main(DnldURLWithoutUsingProxy.java:17)
All outgoing traffic needs to use the proxy wwwproxy (alias to http://proxypac/proxy.pac) on port 80, where it will prompt for valid authentication before allowing to get through.
There is no problem pinging www.yahoo.com from this system.
I am running jdk1.6.0_03, Netbeans 6.0 on Windows XP platform.
I have tried Greg Sporar's Blog on setting the JVM option in Sun Java System Application Server (GlassFish) and
Java Control Panel - Use browser settings without success.
Thanks,
George -
How to read system evenlog using java program in windows
How to read system evenlog using java program in windows???
is there any java class available to do this ? or any one having sample code for this?
Your friend ZoeWelcome to the Sun forums.
>
How to read system evenlog using java program in windows???>
JNI. (No.)
>
is there any java class available to do this ? or any one having sample code for this?>You will generally get better help around here if you read the documentation, try some sample code and come back with a specific question (hopefully with an SSCCE included).
>
Your friend Zoe>(raised eyebrow) Thank you for sharing that with us.
Note also that one '?' denotes a question, while 2 or more generally denotes a dweeb. -
How to run Struts program with the help of tomcat
Hello Everybody
This is Adesh.I am a newcomer of java and facing a problem with struts, so if any one know how to set the path of struts and how to run struts program, so plz inform me.
THX in Advance.............................................struts-config.xml
<struts-config>
<action-mappings>
<action path = "/welcome"
type = "Welcome"
scope="session">
<forward name="success" path=".welcome"/>
<forward name="failure" path=".base.error"/>
</action>
</action-mappings>
<plug-in className="org.apache.struts.tiles.TilesPlugin">
<set-property property="definitions-config" value="/WEB-INF/tiles-defs.xml"/>
<set-property property="definitions-debug" value="1"/>
<set-property property="definitions-parser-details" value="0"/>
<set-property property="definitions-parser-validate" value="true"/>
</plug-in>
</struts-config>tiles-defs.xml
<tiles-definitions>
<definition name = ".base" path = "/include/template.jsp">
<put name = "title" value = "${title}"/>
<put name = "header" value = "/include/top.jsp"/>
<put name = "body" value = "${body}"/>
<put name = "footer" value = "/include/footer.jsp"/>
</definition>
</tiles-definitions>web.xml
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>definitions-config</param-name>
<param-value>/WEB-INF/tiles-defs.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>init</servlet-name>
<servlet-class>Init</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<jsp-config>
<taglib>
<taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-html.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/wall.tld</taglib-uri>
<taglib-location>/WEB-INF/wall.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/c.tld</taglib-uri>
<taglib-location>/WEB-INF/c.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/fn.tld</taglib-uri>
<taglib-location>/WEB-INF/fn.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/fmt.tld</taglib-uri>
<taglib-location>/WEB-INF/fmt.tld</taglib-location>
</taglib>
</jsp-config>
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/SQLServerDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>This should help.... -
How to read system eventlog using java program in windows?
How to read system eventlog using java program in windows?
is there any java class available to do this ? or any one having sample code for this?
Your friend ZoeHi,
There is no java class for reading event log in windows, so we can do one thing we can use windows system 32 VBS script to read the system log .
The output of this command can be read using java program....
we can use java exec for executing this system32 vbs script.
use the below program and pass the command "eventquery"
plz refer cscript,wscript
import java.io.*;
public class CmdExec {
public static void main(String argv[]) {
try {
String line;
Process p = Runtime.getRuntime().exec("Command");
BufferedReader input =
new BufferedReader
(new InputStreamReader(p.getInputStream()));
while ((line = input.readLine()) != null) {
System.out.println(line);
input.close();
catch (Exception err) {
err.printStackTrace();
This sample program will list all the system log information....
Zoe
Maybe you are looking for
-
1.Bridge is slow, it oftens displays a cache error problem on start up even when I have emptied cache. 2.Camera RAW will not display the correct tool eg Adjustment Brush [k] shows the loading circle unless click return. I often have many hundreds of
-
Using COLLECT on a internal table
Hello, I have fetched records from a table into my internal table through, " SELECT * FROM .... INTO TABLE FOR ALL ENTRIES IN ...... " There are two columns in my internal table against which i need a total of the column. COLLECT sums the amounts . B
-
AIR 1.5.3 Generates 1000+ threads on Windows and Crashes...
I'm writing a fairly large AIR application that, at one point, begins creating threads over and over.The thread count will reach 1000+ before finally crashing. Notes: This *only* crashes Windows 7 and Vista The thread count on XP increases the same a
-
How to select the browser for output
Hi all I have two brosers mozilla and internet explorer when i run the application defaulty it's taking the mozilla. how to change it to internet explorer. is there any settings are there in NWDS to select the specific browser. thanks®ards Viswa
-
I can not BUY Mountain Lion - Licensing File???
I try to buy OS X Mountain Lion already since a few hours (more than 16 to be exact) but it always comes up with an error message. When pressing "buy" botton: "Your purchase can not be finalized. The product distribution file couldn´t be validated. I