Executing external program (non-java)
Hello,
I just started programming Java. I installed SunForum3.2 on SunRay some days ago and I was faced with the problem that all that the people who are registered with the GateKeeper-Software are not shown anywhere. So I developed a small app, that read out a file containing the output of the command "registrar -q" ( displays all registered users including their SunForum-name ). Now some people not working on the SunRay-platform would like to connect as well to the SunForum-users. For this reason I'd like to execute "registrar -q" periodically and directly use the output from and within a Java-app but I couldn't find a way to execute the program "registrar -q" so far.
Thanks for your help.
Thomas
Process p = Runtime.getRuntime().exec( "registrar -q" );
Then read the Process's input stream, which should give you the stdout of your command. There are plenty of full code examples of how to do this floating about, and you should have no problem with it.
Similar Messages
-
How to execute external program in java?
My question is how to execute an external program in java.
I need to call a unix command in java.
Thanks.it depends on what you are trying to do. Following are the two methods
1. Runtime.exec() : this method allows you just to call an external program as a seperate process
2. JNI (Native Interface) :- As of right now only C and C++ are supported by this method. This method allows you to directly call the C/C++ methods from JAVA -
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 -
Execute external program from java in the same virtual machine
hello,
I need some help. here is what i need: i'm developing a test tool and i need to execute the application to be tested from my test tool in the same virtual machine so that i can be able to connect to that application and catch events like clicking and so on.
problem is that i do not know how to launch the application i want to test in the same virtual machine as the test tool.
any help would be good,
thanksproblem is that i do not know how to launch the
application i want to test in the same virtual
machine as the test tool.Just invoke the main class of that application.
You probably don't want to hear this, but writing a test tool is not easy if you are going to try to catch events etc. It's probably a bit too hard for you if you don't know how to invoke an app within the same VM.
Kaj -
Executing external programs from PL/SQL?
Hi All,
Is it possible to execute external
programs (i.e. shell scripts, or
perl scripts) from a stored procedure
or trigger?
I know that typically it is the other
way around, but hey try telling that
to my boss.
Thanksyou cant execute any operating system commands from plsql
procedures. but you can achieve result by using either java
stored procedure or pro*C program .
Suresh Vemulapalli -
How to call a external program in java?
Help!!
Is there any method that can a java program can call a external program? For example execute a exe file.
Thanks.Yes.
Runtime.getRuntime().exec("exactly what you would type at the command line");
But be aware that this is operating-system-specific and full of gotchas. When you run into one of them, come back to the forum and do a search, this is a frequent topic of discussion. -
My java application has a feature in which it executes an external program, which creates a file, then shuts down. That's working great.
My problem: how can my program tell when the external program is finished executing, so that it can work with the created file?Basically you just need to call waitFor on the Process object returned from Runtime.exec. See this article for a more detailed discussion: http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
-
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 ? -
Executing external files within java
Could someone pls tell me how i can execute external files, i.e. .bat files within java. thanks.
See java.lang.Runtime and java.lang.Process classes.
http://java.sun.com/j2se/1.4.1/docs/api/java/lang/Runtime.html
http://java.sun.com/j2se/1.4.1/docs/api/java/lang/Process.html
And if you search this site you can probably find a ton of examples.
Keep in mind that using this can limit portablilty of your Java application. -
Executing external programs in Windows from UNIX
Hi all,
I would like to call an external program in Windows box from UNIX box. I tried to create a command in SM69, specify the command and OS type to Windows. When I try to execute the command in SM49, I got an error 'program_start_error'.
I tried also to create an RFC destination in SM59, using connection type = T (start external program via TCP/IP), specifying the program in the Program field and specify the Windows box hostname (or IP add) in the Target host. But this also seemed could not work.
Is there any other ways I could do this?
Thank you.
Mizwan<b>RSBDCOS0 Execute UNIX commands. </b>
Look at <b>SM69, SM49</b> and
Function <b>SXPG_COMMAND_EXECUTE</b>
e.g. SM69
Press F5 or click Change button
Press F6 or click Create
Fill in the following parameter :-
Command name - the unix scripts file name e.g. ZABAPFTP
Operating system command - e.g. sh
Parameters for operating system command - e.g. /sap_production/usr/sap/trans/data/zabapftp.sh
REPORT ZABAPFTP.
data : t_btcxpm like btcxpm occurs 0,
p_addparam like sxpgcolist-parameters,
rep_date like sy-datum,
t_date like SXPGCOLIST-PARAMETERS.
rep_date = sy-datum - 1.
t_date = rep_date.
*p_addparam = '/sap_production/usr/sap/trans/data/zabapftp.sh'.
refresh t_btcxpm. clear t_btcxpm.
call function 'SXPG_CALL_SYSTEM'
EXPORTING
commandname = 'ZABAPFTP'
additional_parameters = t_date
TABLES
exec_protocol = t_btcxpm
EXCEPTIONS
no_permission = 1
command_not_found = 2
parameters_too_long = 3
security_risk = 4
wrong_check_call_interface = 5
program_start_error = 6
program_termination_error = 7
x_error = 8
parameter_expected = 9
too_many_parameters = 10
illegal_command = 11
others = 12.
if sy-subrc ne 0.
write:/ 'Error in ZABAPFTP ', sy-subrc.
endif.
regards
vinod -
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! -
JavaProcessBuilder freeze to execute external program
I am trying to run external program using JavaProcessBuilder class. This program doesn't return any status ( it freeze here: int status = mosesPro.waitFor();) when there are more than 20 lines in my test file (command [3, 4]). I would be very thankful for any solution/suggestion. I have attached my sample code below:
String command [] = new String [5];
command [0] = "/Users/X/tools/moses/moses-cmd/src/moses";
command [1] = "-config";
command [2] = "/Users/X/Documents/thesis/workspace/juneTest/translation/evaluation/filtered.test/moses.ini";
command [3] = "-input-file";
command [4] = "/Users/X/Desktop/test2.input";
try {
child = new ProcessBuilder(command);
mosesPro = child.start();
int status = mosesPro.waitFor();
if (status == 0) {
BufferedReader reader = new BufferedReader(new InputStreamReader(mosesPro.getInputStream(), "UTF-8"));
String line;
line = reader.readLine();
while (line != null) {
System.out.println(line);
line = reader.readLine();
reader.close();
} else {
BufferedReader errorReader = new BufferedReader(new InputStreamReader(mosesPro.getErrorStream(), "UTF-8"));
String errLine;
errLine = errorReader.readLine();
while (errLine != null) {
System.out.println(errLine);
errLine = errorReader.readLine();
errorReader.close();
mosesPro.destroy();
} catch(Exception ex) {
ex.printStackTrace();
}You have a deadlock. The stdout buffer is filling so the process is waiting for space to become available. Space can never become available since you don't read the stdout stream until the process has terminated. You should read the 4 sections of http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html and implement the recommendations.
Note - the 'traps' article is concerned with Runtime.exec() but the traps are just the same with ProcessBuilder. -
Executing C-program inside Java
Hello, my situation is that I am using an open source which is written in C.
I execute this program using the following code.
Process proc=null;
try{
proc=Runtime.getRuntime().exec(cmds);
System.out.println("Execute");
catch(IOException ioex){
System.out.println(ioex);
try{
proc.waitFor();
catch(InterruptedException irex){
System.out.println(irex);
if(proc.exitValue()==0){
System.out.println("The command is normally and sucessfully terminated.");
}where the "cmds" is a normal command line argument using for executing the open source program.
For example,
prompt>./osprogram<input_fileok
-
How to call a external program in java program
for example, if I want to execute internet explore or windows word in java program, how to do it?
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Runtime.html
-
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)
Maybe you are looking for
-
How to get time in hours minutes and seconds subtract between two varchar t
Hi all, I have two varchar variable which has value like this v_outpunch1:='17:50:00' and v_Shifttime:='18:00:00' this both time i am subtracting here and storing in another varchar variable which is like this. v_EarlyLeaverstimeformat := LPAD((extra
-
Cannot format my iMac. Problem with partition's file
I cannot format my iMac because Disk Utility sends an error: The partition map needs to be repaired because there's a problem with the EFI system partition's file system. Any suggestions?
-
I have multiple iphones at my business that we take photos with they are all uploaded to the same icloud account. Is there anyway to tell which phone the photo came from? The info tab doesn't help because they are all iphone 4's.
-
Problem Using BrowserLab on an Intranet site.
I am trying to use BrowserLab to access an intranet site and I keep receiving the message that the URL is invalid. Is it possible to use this tool in this manner? I am not using Dreamweaver for development.
-
Firefox makes a lot of new windows when i try to press on an email link
I press on a link with email address then my firefox 3.6.4 on imac starts to make a lot of new empty windows so they cover my whole screen, hundreds of them. == This happened == Every time Firefox opened == yesterday