Calling an external prgram in java
How would you go about calling an external program like xyz? If xyz is called in the following manner:
xyz info_a=normal info_b=test info_c="text message"
Thanks!
Thanks for the tip.
I got the call now but can someone tell me what this will pass?
Runtime.getRuntime().exec("opcmsg severity=normal application=Runtime object=Notes msg_grp=World msg_text=\"'Test - look\"'");
I can run this when I cut it out and run it command line, but it doesn't run when executed from my program.
Thanks in advance for the help.
Similar Messages
-
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. -
How to call a external software in java program?
for example, if I want to execute internet explore or windows word in java program, how to do it?
// Modified from Just Java
import java.io.*;
public class execDir {
public static void main(String args[]) {
try {
Runtime rt = Runtime.getRuntime(); // step 1
Process prcs = rt.exec("doDir.bat"); // step 2
InputStreamReader isr = // step 3
new InputStreamReader( prcs.getInputStream() );
BufferedReader br = new BufferedReader( // step 4.
isr );
String line;
while ((line = br.readLine()) != null)
System.out.println(line);
} catch(IOException ioe) { System.out.println(ioe); }
Maybe this will help you. -
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
-
How to call external files from java?
How to call external files in java. For example how to call a *.pdf file to open in its default editor(say Acrobat), or a *.html file to open in the default browser or a *.txt file in a notepad etc..,
In my program i have *.chm (Compiled Windows HTML Help) help file. how to open it in its default editor it?Jayarathina_Madharasan wrote:
no one answered my questionHi what wrong did i do...basically insulted all the volunteers here who took the time to consider your question and try to offer you help. Other than that, you did nothing wrong.
From JavaRanch :
And even if an answer doesn't solve your problem, even if it should totally miss the point - the best thing to do to motivate others to continue trying to help you is showing respect and gratitude for the investment of time that was put into dealing with your issue.
Edited by: Encephalopathic on Apr 14, 2008 10:01 AM -
Calling external servlet from java stored procedure
Hello,
I need to call an external servlet which is in 9iAS server ( unix box) from Java Stored procedure in oracle database.
Can anybody give me an idea? is it possible?
Thanks,
ViswaI am trying the same. Here is URL which will help u.
http://otn.oracle.com/sample_code/tech/java/jsp/samples/wsclient/Readme.html
Let me know when you run servlet successfully.
Regards
Satish -
How can I call external exe in java
Hi ,
Is It Possible to call external exe in java.
I read Runtime.exe("some exe") but actually my exe expects some input to process for that how can i pass the input to my exe and how can get the response from exe to my java class.
any sample code is welcome.
Thanks
Babu Hexample
import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.io.*;
public class RuntimeExample extends JFrame {
private JTextArea textArea;
private JTextField textField;
private PrintWriter writer;
public RuntimeExample()
init();
initProcess();
public void init()
textArea = new JTextArea(20, 80);
textArea.setEditable(false);
textField = new JTextField(30);
textField.addKeyListener(new KeyAdapter()
public void keyPressed(KeyEvent event) {
if (event.getKeyCode() == KeyEvent.VK_ENTER)
if (writer != null)
textArea.setText("");
writer.print(textField.getText() + "\r\n");
writer.flush();
textField.setText("");
Container container = getContentPane();
JScrollPane scrollPane = new JScrollPane();
scrollPane.setViewportView(textArea);
container.add(scrollPane, BorderLayout.CENTER);
container.add(textField, BorderLayout.SOUTH);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pack();
textField.grabFocus();
setVisible(true);
public static void main(String[] args) {
new RuntimeExample();
public void initProcess()
Runtime rt = Runtime.getRuntime();
try
//Process p = rt.exec(new String [] {"cmd", "/C", textField.getText()});
//textArea.setText("");
//textField.setText("");
Process p = rt.exec("cmd");
writer = new PrintWriter(p.getOutputStream());
Thread thread1 = new Thread(new StreamReader(p.getErrorStream()));
Thread thread2 = new Thread(new StreamReader(p.getInputStream()));
thread1.start();
thread2.start();
System.out.println("Exit Value = " + p.waitFor());
catch (Exception ex)
textArea.append(ex.getMessage());
ex.printStackTrace();
public class StreamReader implements Runnable
InputStream is;
public StreamReader(InputStream is)
this.is = is;
public void run()
try
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
String data;
while ((data = reader.readLine()) != null)
textArea.append(data + "\n");
reader.close();
catch (IOException ioEx)
ioEx.printStackTrace();
}you can pass input to the exe by using getOutputStream() from Process and get the output from getInputStream() from Process -
Call external command using java
Hi !
I want to call a external command in linux system with java .I am new to this ,so need help ..
Suppose a command is known as "foobar" in linux .generally executed by
$./foobar
What I was thinking is to call this using java and return the output to a file .
how do I do this ?Take a look at ProcessBuilder.
-
Calling external scrips from Java?
Hi,
I am writing a Java application to call an external script, to start with a unix shell script. I need the application to not only call this script but also for the script to return some sort of value or variable to the Java application.
Is it possible for Java to get return variables from external scripts?
Thank you,
PaulThe following code snippet executes a given command and returns an array containing its return code and its standard error output. Hope this helps.
private Object [] performKshCommand(String command) {
int iRet=-1;
String sRet=null;
if (DEBUG1) System.out.println("performKshCommand\n" + command);
try {
Runtime rt=Runtime.getRuntime();
Process proc=rt.exec(command);
InputStream is=proc.getInputStream();
LineNumberReader lnr=new LineNumberReader(new InputStreamReader (is));
sRet=lnr.readLine();
String line;
while((line=lnr.readLine()) != null) {
if (DEBUG1) System.out.println(line);
InputStream is2=proc.getErrorStream();
LineNumberReader lnr2=new LineNumberReader(new InputStreamReader (is2));
while((line=lnr2.readLine()) != null) {
System.err.println(line);
iRet=proc.waitFor();
catch (Exception e) {
if (DEBUG) e.printStackTrace();
if (!DEBUG) e.printStackTrace();
return new Object [] { new Integer(iRet), sRet} ; -
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! -
How to call an external web service from OIM?
Hi,
I have a question on how to call an external web service from OIM within e.g. creating user process? How should it be done; through adapter and task in the process?
Any recomendations?
Thanks in advance!it is not clear to me if you are having problems with calling java code from OIM or if the problem is the web service API.
Lets do some divide and conquer:
Can you create a simple java class that just writes a couple of lines to the log? Please attach this code to the OIM task and make sure it runs.
Once this works we can start looking at the web service call.
Best regards
/Martin -
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 -
Calling an external program!
Salut all, Im using unfortunately Oracle Forms 6i, and I need to call an external program that I have to develop in Java, compiled into .jar. I just wanna use something like java -jar myJar.jar <my params...> but I don´t know how to call external programs from Oracle Forms, in special from 6i.
I have searched this thread passed (Re: Calling JAVA from PL/SQL but didn´t help me so much.
Thanks all for patience!In version 9 and 10 we have a general way of calling out to java thru the Java Importer functionality.
If you cannot upgrade to these later versions and you don't need to get data back from the jar file execution you can always use the Host command to call it directly the way you have outlined. -
Calling an external C function from a C file in JNI
Hello,
I am trying to call an external C function, from a C file which is being called by a Java file. I am getting an unresolved symbol error. I have tried many things like, making the external C function in the format of JNI, etc, etc. It is still not working. I think it has something to do with linking the two C files. If anyone can please answer this, it would greatly help me. here is the code:
HelloWorld.c:
#include <jni.h>
#include <stdio.h>
#include "MyOldHello.h"
#include "HelloWorld.h"
JNIEXPORT void JNICALL
Java_HelloWorld_print(JNIEnv *env, jobject obj)
helloPrint();
return;
HelloWorld.java:
class HelloWorld
private native void print();
public static void main(String[] args)
new HelloWorld().print();
static
System.loadLibrary("HelloWorld");
System.loadLibrary("MyOldHello");
MyOldHello.c:
#include <jni.h>
#include <stdio.h>
#include "MyOldHello.h"
void helloPrint()
printf("\nHello World!\n");
MyOldHello.h:
void helloPrint();
Now i use the Visual C++ command prompt to compile this by saying:
javac HelloWorld.java
javah -jni HelloWorld
cl -Ic:\Java\jdk1.6.0_20\include -Ic:\Java\jdk1.6.0_20\include\win32 -MD -LD HelloWorld.c -FeHelloWorld.dll
and now it gives me the error saying that there is an unresolved external symbol, which is the call to helloPrint in the file HelloWorld.
If anyone knows how to solve this, or how to call external C functions from a C file that is being called from a Java file using JNI, please respond.
Thanks
NickHi,
In your post on velocity review, you did not compile MyOldHello.c. You compiled a C file that included the header file for it and called a method defined in the header. The linker is never going to be able to find the code for this if you do not include the object file for this.
Try this. You will also have to add in any JNI libraries you need to link against but I am sure you could work that out.
cl /c MyOldHello.c
cl /c -Ic:\Java\jdk1.6.0_20\include -Ic:\Java\jdk1.6.0_20\include\win32 -MD HelloWorld.c
cl /LD MyOldHello.obj HelloWorld.obj /FeHelloWorld.dll
[http://msdn.microsoft.com/en-us/library/f35ctcxw(VS.80).aspx]
Cheers,
Shane -
Call a external application without using a webservice
Hi all,
How can we make a call to external application without using webservice from BPEL or OSB.Please share any links to refer.
Thanks,
KiranHi.
Probably the options:
1. Adapters. BPEL PM offers a different set of adapters that allows the process to communicate with external apps
2. PRobably a basic HTTP POST could be an option
3. Writing some code inside a Java Embedded activity
Which application are u trying to communicate with?
thx
best
Maybe you are looking for
-
Error while verifying the sample application in AIS 9.3
Hi All, I am getting an error "Physical table TBC.sales does not exist" similar error for all other tables. Any one got similar error while creating sample application in AIS. Thanks Sudheer.T
-
My iPod says "cannot be synced. The required file cannot be found" it also defaults to apple logo when I try to access photos. I think the issues are linked. Any ides?
-
Creation of service notificatioin with reference error
Hi, will somebody help me to resolve my error encountered when Im creating service notification with reference, having this dialog box appear " SAP office express info " - Express document "Update was terminated". Though the service notification alre
-
Hi all, Can anyone help me getting validation on not allowing special character on field. I need just alpha numeric to be entered in the field. I have a field with datatype varchar2, which is allowing user to add special chars also. Please let me kno
-
My portable external Toshiba hard drive is now unreadable on my MacBook Pro early 2008 aluminum computer. Since updating to Yosemite OS X 10.10.1, I cannot recover my files stored as Time Machine backups on my external drive. In the finder, it cannot