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 application
Thanks, this is very wierd but compard to other OSes seems to work
Similar Messages
-
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. -
How to run another concurrent from Java Concurrent Program?
Hi,
I have one Java Concurrent Program in ebs R12.
I need to run another Java Concurrent Program when first finished.
I can not find a way to start another request from JCP.
Thanks,
msHi ,
this is an example code to check the OS before running the command :
try{
int ch;
Process proc ;
Runtime r=Runtime.getRuntime();
StringBuffer sbuf = new StringBuffer();
String dir = new String();
String osname = System.getProperty("os.name");
if(osname.equals("Windows NT") )
proc = r.exec("cmd /c dir");
if(osname.startsWith("Linux") )
proc = r.exec("df -k");
InputStream is = proc.getInputStream();
while((ch=is.read() ) != -1)
sbuf.append((char)ch);
is.close();
dir = sbuf.toString();
System.out.println(dir );
}catch(Exception e){ System.out.println(e.getMessage());}
bye
Taha -
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.
-
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 , JulioInvoke /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- -
Running COBOL programs from java
I am on a project at the moment where we want the client-server to be written in Java on Solaris Sparc UNIX machines. The thing is we want the server to start a COBOL program and the output from the COBOL program will be the reply to the client. Is this possible and if so how?
Any help gratefully received
Chris
PS We are not looking to buy expensive toolsJNI would be necesssary if you want to call cobol routines from your java program or vice versa. If you want to communicate with another process then JNI is not really necessary. Indeed it is a very difficult API to master and unnecessary complexity. Well the way I was thinking was that your cobol program can accept input from standard input and write to standard output (if there is such a thing in cobol). You can then read the inputstream of the process which you spawned using runtime.getRuntime.exec("mycobolprogram) mechanism...This should work fairly realiably. I am not sure if this is what you are looking for but give it a try by writing a small cobol program which outputs "Hello World" to standard output and then try reading it from a test java program...
-
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); -
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!!! -
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) -
Call visual prolog program from java
Hi friends,
is there someone help me to call ( run) prolog program from java.
i write a parser with Javacc parser generator and stored parsed information in prolog database and I want create some query in java that work in the prolog file.
how can i combine java and prolog programs. i used visual prolog.
Can someone help me?
Thanks you in advance.
yours sincerely,
ksuSince visual prolog can produce dll's, you can use JNI:
http://java.sun.com/j2se/1.4.2/docs/guide/jni/index.html -
Can we run EXE file/ Another Java Program from Java Application? How?
Can we run EXE file and another java program from java application?
Thanks in advanceExample running adobe acrobat
String command = "C:\\Program Files\\Adobe\\Acrobat 5.0\\Reader\\AcroRd32.exe /t "+selectedDocument+" \\\\CONTROL\\HP LaserJet 4L";
Runtime rn = Runtime.getRuntime();
Process process = rn.exec(command);
process.waitFor();rykk -
Jdeveloper runs another program as the selected one
After selecting a program (from Java Examples) and trying it to
run or debug, JDeveloper starts another program which runs
before. This behaviour is independent of the entry in "Default
Runable Class/File" in Project property, Run/Debug tab. If this
entry is empty, the first try to run my program writes in this
field the other program I don't want to execute. How works the
program execution exactly? JDeveloper has to register somewhere
the previous running program and overrule the standard
(executing the selected program). Does anyone know this
difficulty?
Thanks for the hints.Georg,
I have done some testing and am not having any problems with
this.
My suggestion is:
Make sure the samples you want to run are in your project.
Make sure Show enty points on classpath is not selected.
Right-click the program (with a Main()), select Run from the
context menu.
The Run option from the top menu automatically selects (in this
order) the selected program in the navigator, or if one is not
selected, the first one in the project.
The safest way is to right-click the one you want and run it
from the context menu.
Gary
JDev Team -
Running exe files from java applications
Hello All,
Is it possible to run executable files from java applications?
I need to run an exe file on the client from the server machine, the exe could reside on either the server or any other machine on the LAN. Is it possible to specify the path of where the exe resides, and run it on a client machine?HI,
I tried to launch a MS Word application using runtime.exec but it gives me some problem
The foll. code to launch a txt file using notepad works.
Runtime rt = Runtime.getRuntime();
String[] callAndArgs = {"notepad.exe","C:\\coo7\\wizard.txt"};
Process child = rt.exec(callAndArgs);
However, oif I try to launch a MS Word application, it asks for the entire path of WINWORD.exe, (unlike just specifying notepad.exe as the first argument in String[] callAndArgs) and this can vary from one machine to another.. how do I get around this?
The foll. code snippet works but the complete path of where WINWORD.exe might be installed on any machine, is not fixed:-(
Runtime rt = Runtime.getRuntime();
String[] callAndArgs = {"C:\\Program Files\\Office\\Office10\\WINWORD.exe","C:\\coo7\\wizard.doc"};
Process child = rt.exec(callAndArgs);
Any idea/suggestions pls.. -
Running ls command from Java stroed procedure no output
Hi ,
I am trying to run ls command from java stored procedure in oracle
Process p = Runtime.getRuntime().exec("ls");
BufferedReader stdInput = new BufferedReader(new
InputStreamReader(p.getInputStream()));
BufferedReader stdError = new BufferedReader(new
InputStreamReader(p.getErrorStream()));
// read the output from the command
System.out.println("output of the command run:\n");
while ((s = stdInput.readLine()) != null) {
System.out.println(s);
from java stored procedure in oracle.
i get output of println statments but it does not go into while loop to print from stdInput.
Result of running Java stored procedure is -
output of the command run:
Call completed.
when i run the program on client side it works fine.
Has anybody tried this from java stroed procedure.
Thanks,
JagJag,
Actually, the question of whether it works for me seems to depend on the version of the OS (or Oracle). On RedHat Linux (Oracle 8.1.6) it didn't work at all, but on Solaris (Oracle 9.0.2) it did. Here's the output from that run:
SQL> /
output of the command run:
init.ora
initDBPart9i.DBPSun01.ora
initdw.ora
lkDBPART9I
orapw
orapwDBPart9i
spfileDBPart9i.ora
Done
PL/SQL procedure successfully completed.
But, I did need to change a line of your code to this:
Process p = Runtime.getRuntime().exec("/usr/bin/ls");
your original was:
Process p = Runtime.getRuntime().exec("ls");
You might consider, if possible, use of some of the Java File classes instead of ls, as this might make things more predictable for you. There were some examples in oramag.com a few months ago, but they were pretty simple (you might not need them).
Hope this helps,
-Dan
http://www.compuware.com/products/devpartner/db/oracle_debug.htm
Debug PL/SQL and Java in the Oracle Database
Maybe you are looking for
-
Attachments in Mail Won't Download
When I try to download an atttachment - it says its downloading it to the desktop - and then nothing is there? It's an attachment from another person on a MAC - So it's not an issue with Windows or a PC... Help? Miles
-
Hi... I am running a dual core, Win7 64bit PC, with Firefox Regular and Nightly on it... I also have 32bit Win XP Virtual PC on the same PC with Regular Firefox... How do I sync all of them to give me the same bookmarks, history, cookies and password
-
Can I use a natwest debit card for iTunes
Iv have tried creating an apple account but it will not accept my natwest debit card for payments
-
Working on: CentOS 5.5 Glassfish 3.0.1 (the new Oracle branded one :D) JDK 1.6.20 Did work previously with apex listener build: apex_listener.0.10.110.10.57 (configured manually...could never get the roles and users straight before the guide) Redeplo
-
Is anyone else having problems with App Store not processing updates?
For last 36 hours, App Store is not processing updates. Rebooted, and hard rebooted. Tried tapping on apps to force a download, from the Purchased list and the home screen. Ipad also will not access new 8.1 version today. Any suggestions?