Using Runtime exec() method to run java files and return runtime errors
Hi
I'm writing a java editor and I use
Runtime.getRuntime().exec(command)
to compile the java files. That works fine and I deal with the returned errors using the getErrorStream().
My questions are:
1. Can I use the same technique for returning runtime errors. In any posts I've read the process runs from begining to end, returning the errors after completion. How do I return the errors of the app as they happen interactively?
2. If i cant use the exec and getErrorStream() methods then does anyone know how it is done?
Thanks in advance for any help!
Read this:
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
MOD
Similar Messages
-
Java's Runtime.exec() method
When you shell out to java's Runtime.exec() method, are the process name and arguments the same for the child process that is spawned.
We see duplicated processes about the time when our logs tell us this command was run. However, we cannot seem to reproduce this. Has anyone else seen anyone this before?That's what I though too. But check this out . . .
Our code looks as follows:
private Runtime rt;
private Process p;
rt = Rutime.getRuntime();
p = rt.exec(command);
This exec() call creates a new process, which is a child of the java process that runs this command. The final process looks like the "command" string that is passed to the exec() method call. In our case, the command is a call to the /usr/bin/mail utility to send out faxes and emails.
We ran a very tight loop executing the rt.exec() call over and over. What we found was that for a minor fraction of a second, the newly created process looks just like the original process including the same arguments. However, the PID's indicated that one process was the child of the other. This is why it looked like we had 2 of the same processes. WILD!
Thanks guys! -
The Runtime.exec methods doesn't work well on Solaris ???
I have two threads and I set the different running time.
I use Runtime.exec to a run the command and use Process to get the process.
It works properly in the windows2000 platform.
However, when I transfer the platform to Solaris...and run the program...
Two threads always at the same time....It is very wired....I always debug
for 2 days....
(at first I run "vmstat 1 2" command, later I change to "ls","rmdir"....etc,
all of them don't work.....
If I close the Runtime.exec..........Everything works well......)
And I study the API. I found this message...
The Runtime.exec methods may not work well for special processes on certain
native platforms, such as native windowing processes, daemon processes,
Win16/DOS processes on Win32, or shell scripts. The created subprocess does
not have its own terminal or console.
Could someone share her/his experience.....:(
And if any other way I can run command inside java code instead of
Runtime.exec.....???
Please reply my mail to [email protected] I do appreciate your kindly &
great help!!!!!!!!
This is my code.......
import java.io.*;
import java.lang.*;
import java.util.*;
* <p>ServerThread1</p>
* <p>??�X???��?�D???�X???, "Vmstat 1 2".</p>
class ServerThread1 extends Thread{
private ServerAgent Sa;
public ServerThread1 (String Name, ServerAgent Sa){
super(Name);
this.Sa = Sa; file://Assign ServerAgent reference Sa
public void run(){
while(true){
try{
Thread.sleep(5000);
catch (Exception e){
System.out.println("ServerThread1 fails");
System.out.println("Thread1 is running.");
try {
Runtime rt1 = Runtime.getRuntime();
Process proc1 = rt1.exec("mkdir"); ------>If I close
rt1.exec , two threads works seperately...........:(
catch (Exception e) {
System.out.println("Thread1 Error");
class ServerThread2 extends Thread{
private ServerAgent Sa;
public ServerThread2 (String Name, ServerAgent Sa){
super(Name);
this.Sa = Sa;
public void run(){
while(true){
try{
Thread.sleep(15000);
catch (Exception e){
System.out.println("ServerThread2 fails");
System.out.println("Thread2 is running.");
try {
Runtime rt2 = Runtime.getRuntime();
Process proc2 = rt2.exec("vmstat 1 2"); ----->If I don't run
the rt2.exe, two threads work seperately....
catch (Exception e) {
System.out.println("Thread2 Error");
public class ServerAgent{
private Vector v1 = new Vector();
private Vector v2 = new Vector();
private Hashtable currentData = new Hashtable();
private static String startUpSwap = null;
private static String startUpMem = null;
public static void main(String[] arg) {
ServerAgent s = new ServerAgent();
ServerThread1 st1 = new ServerThread1("Thread1",s);
ServerThread2 st2 = new ServerThread2("Thread2",s);
st1.start();
st2.start();If I close the Runtime.exec..........Everything works
well......)You don't empty the output of the command, that blocks the process.
A citation from
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
Why Runtime.exec() hangs
The JDK's Javadoc documentation provides the answer to this question:
Because some native platforms only provide limited buffer size for standard input and output streams, failure to promptly write the input stream or read the output stream of the subprocess may cause the subprocess to block, and even deadlock.
Try out something like this:
String s;
try {
Process myProcess =
Runtime.getRuntime().exec("ls -l"));
DataInputStream in = new DataInputStream(
new BufferedInputStream(myProcess.getInputStream()));
while ((s = in.readLine()) != null) {
out.println(s);
catch (IOException e) {
out.println("Error: " + e);
}Another source of trouble under Unix is not having the correct permission for that user that executes the Java VM, which will be the permissions for the spawned subprocess. But this probably not the case, as you see something after exit.
Regards,
Marc -
How to run java file by using another applet file ??
how to compile and run java file by using another applet or japplet file .
how to understand what you are talking about.
-
How to compile and run java files on a mac using command line?
can someone tell me or link me to some article on how to compile and run java files from command line on a mac? I have mac OS X leopard
What do you mean by "where to put them" ? What do you want to put anywhere ?
Have you read Peter's comment in brackets ? Perhaps you have a classpath problem ?
Edited by: Michael_Knight on Aug 31, 2008 4:23 AM -
How to compile other java files and run them from my own programs?
I'm developing a unit testing tool for AspectJ, which can originally generate the stubs for aspect unit to be tested. All these stubs are java files. After generation of stubs, how can I program the code to compile this unit together with these stubs, i.e. how can I put the functionality of compilation and run, e.g. command "javac *.java" and "java *", into my own code.
Hope you can understand what I mean.
Thank you in advance.When I use Runtime.getRuntime().exec(command) for executing the AspectJ compile command "ajc", "IOException createProcess error=2" always occurs, while it is ok for Java comiple command "javac".
Why this happens when I use Runtime.getRuntime().exec("ajc Hello.java Test.aj")? Is it the reason that Runtime.exec(String) may not support any command in DOS?
(ajc is the compile command for the java file and aj file.)
Thank you in advance. -
Where is the running JAVA file is located
Hey,
lets say my java file would be in C:\package1\whereIam.java
if I run this program, how can I ask (command ?),
in which directory the running java file is located.
i.e. I would like to get C:\package1
AykutIt's actually more complicated than that. The class could be in a jar file... would you want the directory the jar file is in? Well, I'll let you deal with those issues. You can get a URL to your class like this, I think:URL me = this.getClass().getResource("/" + this.getClass().getName());
-
How can i run java file by double click like Visual basic
i have to run java file by giving a command on DOS promtp.But in Visual basic i easily make a .exe file to run my program. Does java provide this thing?
please help me.If you have intaled a JRE in your computer, at leasrt in windows, the .jar files are asociated with the VM, so a double click on them will execute the, thats how things work on my computer, with jdk 1.4 installed.
Abraham. -
How to run .java file in windows ?
How to run .java file in windows without installing any program? Thx!
First, U must make sure that there is JDK on your computer
Then, set the envionment variables which the os can find your compiler and interpreter: javac java
after those, you must complie your .java file to .class file, then you can excute it by java, for example " java helloworld" -
Use System Exec IrfanView to open JPEG file
I am trying to use System Exec to call Irfanview to open a Jpeg file, and the following error occurs:
"Error 2 occurred at System Exec.vi. Command was "iview32 c:\test3.jpg /hide=3 /pos=(30,30)"
"LabVIEW: Memory is full."
"NI-488: No Listeners on the GPIP"
I then tried to add "cmd /c" in front of the command but the DOS windows just flash open and close and then nothing happen.
I have no problem opening the jpeg in DOS command window.
Anyone can help?
Solved!
Go to Solution.you do not need to specify the full path as long as you have the path in your path variable
I think the problem may be that you are using the wrong program name I think it is i_view32 not iview32
- James
Using LV 2012 on Windows 7 64 bit -
i downloaded Yosemite and now I cannot open CS 5.5 Production Premium at all, I receive the message that i need to install the legacy Java SE6 runtime. I am running Java 8 Update 25 (the latest). I have uninstalled and reinstalled CS5.5 Prod Prem already again so please don't suggest this. What do I do?
Try to install java from below link and try once
Java for OS X 2014-001 -
I'm using a 15" Macbook Pro running OSX6.8 and cannot upgrade. I have a subscription to Adobe CC but none of these work on this so I was on with Adobe for 5 hours trying to install and launch Illustrator, InDesign, Photoshop, Muse, and Acrobat Pro from CS6. Well, InDesign is the only one that works and I have a ton of work due! I don't have a serial number for Photoshop or Illustrator except for CS3, and they don't work. InDesign gave me no problems. Illustrator says it can't work on this machine. Photoshop needs a serial number. I'm stumped and getting anxious and freaked out. Can anyone help? Adobe Chat is down right now.
if you have a cc subscription, close ps > sign out and then back in to your cc desktop > open ps.
ai cs6 requires:
Multicore Intel processor with 64-bit support
Mac OS X v10.6.8 or v10.7. Adobe Creative Suite 5, CS5.5, and CS6 applications support Mac OS X v10.8 and v10.9 when installed on Intel-based systems.*
2 GB of RAM (8 GB recommended)
2 GB of available hard-disk space for installation; additional free space required during installation (cannot install on a volume that uses a case-sensitive file system or on removable flash storage devices)
1024 x 768 display (1280 x 800 recommended) with 16-bit video card -
How to run .class file and .jar file in jdev9i
I want to run .class file and .jar file in jdev9i,what should I do?
Also,I want to generate .class file and .jar file in jdev9i,what should i do?Add the .class file containing the public static void main(...) method to the project by clicking on the + toolbar button in the navigator, open the project properties and properly set the additional classpath then right click on the .class in the navigator and say run. It should work, I've just tried it.
Doesn't work for a .jar yet, in JDeveloper 9.0.3 it works both for .class and .jar
Michel -
In our current application we have the following source directory structure:
src -
- com
- edeploy
- subdirs ... (many directories here)
- jsp
-subdirs ... (many directories here)
In com.edeploy.subdirs, there exists *.java files, and *.gxq files (query
files). I would like to modify my build.cmd script to copy the *.gxq files
into the same directory as the class files.
Here's my script so far:
@REM Create list of files to compile
DIR /S /B /A:-D src\com\*.java >class.list
@REM Create list of query files
DIR /S /B /A:-D src\com\*.gxq >query.list
@REM Compile
javac -d stage\WEB-INF\classes @class.list
@REM Copy query files into class directory
.......... code needed here ......
Can anyone help me with this?
Thanks,
Matt
You may want to check out:
http://jakarta.apache.org/ant/index.html
Gary
"Matt Raible" <[email protected]> wrote in message
news:[email protected]..
> In our current application we have the following source directory
structure:
>
> src -
> - com
> - edeploy
> - subdirs ... (many directories here)
> - jsp
> -subdirs ... (many directories here)
>
>
> In com.edeploy.subdirs, there exists *.java files, and *.gxq files (query
> files). I would like to modify my build.cmd script to copy the *.gxq
files
> into the same directory as the class files.
>
> Here's my script so far:
>
> @REM Create list of files to compile
> DIR /S /B /A:-D src\com\*.java >class.list
>
> @REM Create list of query files
> DIR /S /B /A:-D src\com\*.gxq >query.list
>
> @REM Compile
> javac -d stage\WEB-INF\classes @class.list
>
> @REM Copy query files into class directory
> .......... code needed here ......
>
> Can anyone help me with this?
>
> Thanks,
>
> Matt
>
>
-
Revision: 10059
Author: [email protected]
Date: 2009-09-08 11:31:48 -0700 (Tue, 08 Sep 2009)
Log Message:
update two package-info.java files, and add one new one.
Modified Paths:
blazeds/trunk/modules/proxy/src/flex/messaging/services/http/proxy/package-info.java
Added Paths:
blazeds/trunk/modules/core/src/flex/messaging/util/concurrent/package-info.java
blazeds/trunk/modules/core/src/flex/messaging/validators/package-info.javaRevision: 10059
Author: [email protected]
Date: 2009-09-08 11:31:48 -0700 (Tue, 08 Sep 2009)
Log Message:
update two package-info.java files, and add one new one.
Modified Paths:
blazeds/trunk/modules/proxy/src/flex/messaging/services/http/proxy/package-info.java
Added Paths:
blazeds/trunk/modules/core/src/flex/messaging/util/concurrent/package-info.java
blazeds/trunk/modules/core/src/flex/messaging/validators/package-info.java
Maybe you are looking for
-
Max no of records in select-options
Hi, I have a select option for MATNR. I want to perform a validation where in the values given for selection should not exceed 500 material Numbers. How can I do that? Regards, Vinod.
-
Itunes 7 upgrade will not install. Do not have privileges to modify file.
I have been having problems with itunes in that when I open itunes and then close it, my volume is no longer available. So I have been trying to install an updated version of 7.1 but when I try to install it says I do not have permission to modify fi
-
Why do youtube videos blink when you scroll up and down the page?
<blockquote>Locking duplicate thread.<br> Please continue here: [/questions/788365]</blockquote><br> for some reason out of the blue youtube blinks when I am scrolling on a page while playing a video. I tried deleting the cookies which appears to hav
-
How do I sell a series of books as a set on iBookstore/itunes?
How do I sell a series of books as a set on iBookstore/itunes? Can I set a special price?
-
Hi, can you please tell me how can i update database 'z' view. can we update as the same ways as we fill the data in database table by insert update command.. if there is any way to fill data in data base view please describe the process if any code