Problems running external programs from java
Hello.
I wrote a pair of perl scripts and a GUI in java to run them. The first perl script just read the files in one directory makes some changes to the names of the files and then group all this files in a set of new directories. The other perl scripts takes all this new files and calls BLAST sequence alignment program and perform some alignments among these sequences. I tested this scripts and they work fine.
The problem comes when I try to run them for the JAVA GUI. I use RunTime and when I need to run the first perl script it all works well, but when The call to the second perl script is made the program fisishes without doing anything at all. I found out that the problem is that when running the script from the Java GUI it's not able to find BLAST program. So I guess that Java is not really starting a terminal session and it doesn't read my bash_profile to find out the path to my programs.
So, my question is if anyone knows a method to tell Java to load all this paths in the bash_proflie file so all of my scripts work???.
I have no idea is this can be done and how so any advice would be really wellcome.
By the way, my java version is 1.4.2 and my OS is Mac OS X 10.3
Thanks a lot , Julio
Invoke /bin/sh -c and give it your program's full path with.
(To understand what I've written, maybe reading
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps_p.html
http://mindprod.com/jgloss/exec.html
and
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Runtime.html
(especially the exec(String[] cmdarray) method)
might help)
-T-
Similar Messages
-
Pocket PC -Problem executing external program from java
Hi,
I'm developing an application on Dell Axim x51 PDA. I am using mysaifu jvm. The application needs to execute an external program (.exe) for which I'm using the Runtime class.
I get java.io.IOException: The system cannot find the file specified.
I have verified that the file exists. ( i used File class to check if the file exists)
here's the part of code :
Runtime rt = Runtime.getRuntime ();
File sktScan = new File("\\My Documents\\RFID\\ScktScan.exe");
if(sktScan.exists())
System.out.println("FILE EXISTS");
String command = sktScan.getAbsolutePath();
process = rt.exec (command);
System.out.println("Socket Scan Path is : "+command);You have acces to "java.lang.Runtime currentRuntime.exec()" method ? in my case NetBeans IDE dont give me for my compilation with :
microedition.configuration CLDC-1.1
microedition.profiles MIDP-2.0 -
I want to run this program from my java code,
In Linux(ubuntu) I write this command to open the program window
$ paraFoam -case /home/saud/OpenFOAM/OpenFOAM-1.5/run/tutorials/icoFoam/cavity/In my java code I wrote it like this("/home/saud/OpenFOAM/OpenFOAM-1.5/bin/" is the path of the program):
String command = "/home/saud/OpenFOAM/OpenFOAM-1.5/bin/paraFoam " +
"-case /home/saud/OpenFOAM/OpenFOAM-1.5/run/tutorials/icoFoam/cavity/";
final Process myProcess = Runtime.getRuntime().exec(command);
BufferedReader buf = new BufferedReader(new InputStreamReader(
myProcess.getInputStream()));
String line;
while ((line = buf.readLine()) != null) {
System.out.print(String.format("%s\t\n", line));
buf.close();
int returnCode = myProcess.waitFor();
System.out.println("Return code = " + returnCode); Return code = 0
but the program is not opening
Edited by: Saud.R on Apr 11, 2009 3:37 AMWelcome to the Sun forums.
I am not sure of the answer to your question, but people who use Processes regularly, warn other users to ensure they are also doing something with the error stream of the process, otherwise it can hang as you describe. -
Calling external programs from Java?
Hi All,
Is there a way of calling external applications from Java without using Runtime.exec(). That method seems quite messy when you are dealing with streaming data from an input file to an output file. Basically what I'm asking is there a way to run a command the same way you would type it in a command shell?
ThanksLeWalrus wrote:
Ok, I've an external application that I want to be called inside a Java GUI. It has several input arguements, which the format looks something like:
programname inputfile > outputfile
Simple enough.
>
Works fine from a shell command line. From what I understand, this won't work using Runtime.exec() because that method will just start the application. Works fine from Runtime.exec(). Since you are'>' to write stdout to a file you need to us a shell to execute the command.
String[] command = {"sh", "-c","programname inputfile > outputfile"};
Process process = runtime.exec(command);
You need to read, digest and implement the recommendations given in http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html .
File input and output from the application has to be taken care of programatically (java.io stuff). Fine if you've only one input and output. But if you have several input files and hundreds of output files, where does this leave you. It would be much easier if you could pass a string command to the shell directly as if you typed it in the command line yoursel! -
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 do i launch one Java program from another?
both .class files and the JRE directory are in the same directoryYou can use Runtime.exec() to run it as a seperate process, or you can always instantiate your secondary class. Do a search on the term "runtime.exec()" befure you go spawning another thread asking how to use it. That particular subject has been done to death many times already.
-
Starting a external program from java
hi iam trying to start MySQL server from java, the command in dos is as follows C:\mysql\bin\mysql -u username -p ,then the user hits return and the user is prompted to enter a password. i have got as far as entering the the C:\mysql\bin\mysql -u username -p but dont know how get the prompt back to the java program i would be greatfull if anyone could tell me where iam not doing,heres my code so far
try{
Runtime r=null;
r=r.getRuntime();
Process p=r.exec("C:/mysql/bin/mysql -u mark_r -p");
p.waitFor();}
catch(Exception ex){System.out.print("Error");}}You should try using the getOutputStream() and getInputStream() methods for the Process object. Each returns either an inputStream or OutputStream object.
You should be careful if the mySQL password is added to the command since anyone doing a 'ps' on the machine could see the password. -
Running another program from Java on OSX
I have an application that allows the user to specify an external program to run using the Process class, they just have to xpecify the path.
On OSX most of the apps are in .app packages with the contents hidden to the filechooser. What command do I need to run to start (for example ITunes) an applicationThanks, this is very wierd but compard to other OSes seems to work
-
Running external program from Form6i
I have a Form 6i, client server application and from there I launch a window based help system, using Host command.
Is it possible to run both the form application and the help program togather at the same time. As at the moment I need to close the help program to start using my Form based application.
Regards
EVAHi,
I had a similar query and got the following reply and it looks better. Attaching it for ur reference and hope it will help u.
Thx.
R. Magesh.
Magesh
unregistered posted May 15, 2001 08:25 AM
Hi,
Thx. for ur reply but I am already using the same host command and it is working fine. But we do have some problems in using the host command like u need to close the external application or o/s based application before working back in forms and also that I would like to use a generic html tag which can be opened in any default browser defined for the system rather than mentioning or invoking explorer explicitly. I am looking for any new builtin available in FORMS6I which can support web integration with the application.
Thx.
R. Magesh
quote:
Originally posted by Fan Liu ([email protected]):
try this:
http:
host('explorer http://www.oracle.com');
email:
host('explorer mailto:[email protected]');
IP: Logged
Duncan Mills ([email protected])
unregistered posted May 15, 2001 09:14 AM
If you want to start a Host type command Asynchronously then you can use DDE.APP_BEGIN or the WinExec call in the D2KWUTIL library.
<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Eva Maria Villoria ([email protected]):
I have a Form 6i, client server application and from there I launch a window based help system, using Host command.
Is it possible to run both the form application and the help program togather at the same time. As at the moment I need to close the help program to start using my Form based application.
Regards
EVA <HR></BLOCKQUOTE>
null -
Controlling external programs from Java
Hi,
I try to invoke an external command-line program in Windows 2000 fron Java. I do this by
Process proc = Runtime.getRuntime().exec(cmd);
cmd is a String representing a command. For instance I try to control the gnupg program by
"cmd /c C:\\gnupg\\gpg --list-keys"
This works fine. But when I want to make a more advanced control, when gnupg waits for more than one input, and that input can't be put on the same line I get problems.
When running gpg --edit-key SomeKey on the command line I have to enter
trust - return - 5 - return - yes - return - quit
How do I do this?this is how to do it! gotta listen to the output to prevent deadlock. you can pass in parameters o the initial call as well (a string array, where string[0] = command, string[...] = input argument) or write it to the output stream of the process.
hope this helps
public void run_command(String starting_command, String[] further_commands)
Process proc = Runtime.getRuntime().exec(starting_command);
Listener.make(proc.getInputStream());//these listen to the streams
Listener.make(proc.getErrorStream());//which prevents deadlock
PrintWriter writer = new PrintWriter(new OutputStreamWriter(proc.getOutputStream()));
for(int i = 0;i < further_commands.length;i++)
writer.println(further_commands);//you could put the extra stuff as the first string in this array
import java.io.*;
public class Listener extends Runnable
BufferedReader reader;
public static void make(InputStream in)
Listener l = new Listener(in);
Thread thread = new Thread(l);
thread.start();
public Listener(InputStream in)
reader = new BufferedReader(new InputStreamReader(in));
public void run()
String string;
while(true)
string = reader.readLine();
try
Thread.sleep(1000);
catch(Exception e) -
Hi all,
I'm trying to execute a dos program using:
runtime.exec("dos_prog.exe")
THE PROBLEM : in this way I can run only
WINDOWS programs and NOT DOS progs.
What to do ???Hi all!
I'm tring to run a file.bat that execute an exp from locale Oracle server. But when I run it, in dos consol it appaire just only the EXP USER/PASS ....., and don't execute never!! Really, the files of .dmp and of .log, they are created, ...but empty!!!! Why???
........ source .......
Runtime rt = Runtime.getRuntime();
Process rtProcess = rt.exec("cmd.exe /C file.bat");
// wait for command to terminate
try {
rtProcess.waitFor();
catch (InterruptedException ire)
System.err.println("Thread interrupted " + ire.getMessage());
// check its exit value
if (rtProcess.exitValue() != 0)
System.err.println("exit value was non-zero");
// close stream
bReader.close();
........ file.bat .......
@echo off
EXP USER/PSW FILE=EXPFILE.DMP LOG=FILELOG.LOG OWNER=MYOWNER
If you want, you car reply me directly at [email protected] - Thanks very much!!! -
Help with running external programs within java
Hi,
I'm new here, and not sure whether i'm in the right place for this, but i thought i'd give it a shot anyway!
Basically i have a fortran program already written, that takes in the name of a text file as an input. I'm wanting to create a user interface to create this text file, and then i would have a button or something to enable me to then run the fortran program and input the file all from the user interface, and get rid of the need to manually run the fortran program.
Firstly, is this even possible?! Is it difficult to program and get to work?! Does anyone have any suggestions or guidance on this.
Thanks@Op.
..and here are two links related to that.
http://java.sun.com/developer/JDCTechTips/2003/tt0304.html
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html -
hi
i have a program with extension .rcw and i want to run from a java program. can anyone show me the code that can help me to call this type of files or any type of files
Thanks in advance.** Here is a pure Windows solution
** Run the code and you will be taken to a tutorial
that may provide
** a more generic solution
public class WindowsProcess
public static void main(String[] args)
throws Exception
String[] cmd = new String[4];
cmd[0] = "cmd.exe";
cmd[1] = "/C";
cmd[2] = "start";
cmd[3] =
=
"http://www.javaworld.com/javaworld/javatips/jw-javati
p66.html";
// cmd[3] = "notepad";
// cmd[3] = "will.xls";
// cmd[2] = "a.html";
// cmd[3] = "file:/c:/java/temp/a.html";
Process process = Runtime.getRuntime().exec( cmd
md );
}i really don't know what to say. You really help me.
I'm really thankfull to you -
Cannot run batch program from Java Application
Hi All,
Im trying to run a batch file under windows from my Java Program. The batch file is located in the following path:
C:\Program Files\MyApp\runme.bat
The above-entioned path contains white space which is not allowed in NT.
Im trying following code:
import java.io.*;
public class Exec {
public static void main(String args) {
try {
Runtime.getRuntime().exec("cmd /c start C:/Program Files/MyApp/runme.bat");
}catch(Exception ex){ ex.printStackTrace();}
How to run this file?
Thanks in advance.
Ketan Malekaror use the overload that takes an array of strings as argument
String[] command = {"cmd", "/c", "start", "C:/Program Files/MyApp/runme.bat");
Runtime.getRuntime().exec(command); -
Invoke external programs from Java
I am running a Java program which will be used to invoke other command line programs in Windows.
However, it seems Java has problem in checking the termination state of command line programs in Windows. In the example below, the pp.waitFor() will keep waiting even if the command completed execution. I try the same code below in Unix and it works without problem. Is there anyone has come across the same problem before ?
I am using JDK1.4.1.
try {
Process pp = null;
BufferedInputStream bi = null;
pp=Runtime.getRuntime().exec("dir");
bi = new BufferedInputStream(pp.getInputStream());
pp.waitFor();
int size=bi.available();
while (size>0) {
byte[] buf = new byte[size];
bi.read(buf);
System.out.println(new String(buf));
size=bi.available();
} catch (Exception e) {
System.out.println("Exceptions !!!");
System.out.println(e.getMessage());I found this article rather helpful:
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
Maybe you are looking for
-
E.g. on this submission page there is cliveeb Inbox Other Apps where logically you'd expect the handtool to materialise when hovering over these areas. Nothing happens which means I cannot select those "buttons/drop downs".
-
Early 2008 24" imac ram upgrade issues
Hi everyone. Hope you guys can help diagnose a problem I have with my imac. It's an early 2008 24" imac with 3.06 Ghz processor and an NVIDIA Geforce 8800 GS 512 graphics card. After buying Empire: Total War I thought it best to upgrade the 2GB RAM
-
The newest release of Java (7.0.250) simply will not run on Firefox 22. I have tried all the "fixes" posted on the Mozilla site -- enabled in both the browser and the Java control panel. The new release of Java works just fine in IE and Chrome.
-
I have a problem with installing anything
when i push the install button, Safari tells that can not open the adresses that start with aam://
-
Preview app will only open 20 images
Hi. For me, the Preview app will only open 20 separate images at once. When I open the 21st image, it opens in the 'drawer' of the 20th image, as do subsequent images I open. This is not the behaviour I want. I want to be able to open any number of i