Calling c code from java
hello everyone
I have question
I need to call c program from java
I don't have problem with application or exe file in c it is working but when I call it from java it doesn't work there is no error but it doesn't work because when I execute the c program the black screen must be appeared so that I can enter the input file and then it produces the output file but in java I cann't see the black screen so please can you tell me the problem
I have used the following code to call c from java:
String line;
String output1 = "";
Process p = Runtime.getRuntime().exec("cpp.exe");
BufferedReader input = new BufferedReader
(new InputStreamReader(p.getInputStream()));
while ((line = input.readLine()) != null) {
output1 += (line + '\n');
input.close();
Hi,
Try this in your code
p.waitFor();It is for waiting of the process till the completion of the I/O.
Regards
Similar Messages
-
How to call c++ code from java
i have a third party dll written in c++. I want to call its methods in java. I searched web and found that I have to use JNI for this. I have seen examples on web writing c++ code and then using it from java through JNI, but can anybody please point to me the example where i have a predefined library or dll in c++ and i have to call it in java. I think that I may have to declare methods in library as native in java and then write a wrapper implementation (dll) in c++ which actually calls the library or dll functions. But, then how will I call methods of dll from my wrapper code.
Any examples, please point
Regards,
FarooqThere's a JNI forum here that may be a better place for this question; though given the general nature of the question, I suspect that they'll refer you to a tutorial. good luck.
-
How to call C/C++ - Code from Java?
I would like to know if it is possible to call C or C++ - Code from Java and how to do.
In short, yes you can do this.
Have a look at http://java.sun.com/docs/books/tutorial/native1.1/concepts/index.html
to see how...
Good luck! -
Calling native Objective C code from Java Script
Hi,
I want to call native objective C code from Java script.
I know one way by using : webView:shouldStartLoadWithRequest:navigationType
Is there another way of doing same?
Thanks,
Ganesh Pisal
Vavni IncAre any of those threads calling java code? If yes then are you calling the Attach method?
-
Call .bat file from java code
I need to call an application that uses a .bat file to execute from a java program. Is that possible?
This is the .bat file:
importcli.exe ciaf2735 C:\Importcli\files\SAI2735*.txt
importcli.exe ciaf2735 C:\Importcli\files\CI2735*.txt
importcli.exe ciaf2735 C:\Importcli\files\SC2735*.txt
importcli.exe db1800 C:\Importcli\files\*.mdbmagaupe wrote:
I need to call an application that uses a .bat file to execute from a java program. Is that possible?
This is the .bat file:
importcli.exe ciaf2735 C:\Importcli\files\SAI2735*.txt
importcli.exe ciaf2735 C:\Importcli\files\CI2735*.txt
importcli.exe ciaf2735 C:\Importcli\files\SC2735*.txt
importcli.exe db1800 C:\Importcli\files\*.mdb
Hmmm, I wonder what would happen if there were a web search engine and you could research like this:
[http://www.google.com/search?hl=en&q=call+.bat+file+from+java] -
Curious thing while calling a procedure from Java !...
Hi !. My name is Agustin and my doubt would be the following one... I am working for a e-business comp and they asked me to call a procedure from java... The code is the following one:
CallableStatement cs = null;
System.out.println("Fecha Nro. 1: " + paramFechaDesde);
System.out.println("Fecha Nro. 2: " + paramFechaHasta);
try
cs = getDBTransaction().createCallableStatement("{call paq_w_ListadoSiniestralidadART. p_sinsiniest(?,?,?,?) }",0);
cs.registerOutParameter(4,OracleTypes.VARCHAR);
cs.setInt(1,paramContrato.intValue());
cs.setString(2,paramFechaDesde);
cs.setString(3,paramFechaHasta);
cs.setString(4,paramNombreArchivo);
cs.executeQuery();
String nomArchivo = cs.getString(4);
System.out.println("### " + nomArchivo +" ###");
catch(SQLException e)
The weird thing is that, I was expecting a big big exception but the only thing I got is
### Error ###
The String I am expecting is a file's name !; so I am a little bit confused...
Also I didn't know where to post so If it's in the wrong category... I apologize !... If anyone need more details, I'll be checking out... The account I am working on is an Insurance company, who is the one who provide access to the DB and the procedures... So I can't check what's inside...Please provide your Java and OS versions, the JDBC jar file and the Oracle DB version being used when you post.
>
I was expecting a big big exception
>
Then why do you have an empty exception block? That just makes it disappear so you won't see one if it happens.
And your code has
cs.registerOutParameter(4,OracleTypes.VARCHAR);
cs.setString(4,paramNombreArchivo);You use 'registerOutParameter' for an OUT parameter and the 'setXXX' methods for other parameters.
Remove the 'setSTring' for the OUT parameter.
Then as malcollmmc already said
>
Sounds like the PL/SQL is returning "Error" as the 4th parameter of the call
>
The actual value returned by PL/SQL is strictly determined by the PL/SQL code and Java and JDBC are not involved.
Fix the code problems, retest, and folllowup with whoever wrote the code if it still returns ERROR. -
How to call a servlet from java?
your help is greatly appreciated..Welcome to the forum
You seem to be misunderstanding something. Do some googling to learn what you need about servlets. Simplified, servlets are java code that's hosted by a web container, such as Tomcat. When a servlet gets called as a consequence of someone requesting a url from the container, it takes in a request object and a response object. All the magic is then in creating an appropriate response (e.g. html) for the incoming request. -
How to Call C++ Method from Java
I need to call C++ method from Java.
I have gone through the JNI tuorial , but was not able to pin point things.
I read that :
You have to write JNI c functions which then call your C++ member functions.You need to write a JNI function which will call new on your C++ class.
Now i have java class :
Java Code JavaClass.java ---->
class JavaClass{
public native void nativeMethod();
static
System.loadLibrary("NativeCppCode");
private void callCppMethod()
//call C++ method
JavaClass jvc = new JavaClass();
jvc.nativeMethod()
}Cpp Code:
NativeCppCode.h---->
class NativeCppCode
public:
getValue();
setValue();
private:
int a;
JNIEXPORT void JNICALL Java_JavaClass_nativeMethod(JNIEnv *env
,jobject obj);NativeCppCode.C---->
NativeCppCode::getValue()
return a;
NativeCppCode::setValue()
a = 1;
JNIEXPORT void JNICALL Java_JavaClass_nativeMethod(JNIEnv *env
,jobject obj)
NativeCppCode* nativeInstabce = new NativeCppCode();
NativeCppCode.setValue();
}Is this the correct way to do it.
Any suggestion would be a great help to metryit wrote:
I need to call C++ method from Java.Not possible.
JNI uses C methods.
Is this the correct way to do it.Same way you would do it in any C/C++ method (not java)
MyClass* p = ....
p->doit();
Common idiom for the pointer in the above is to pass it back and forth to your java code as a java long. You cast it it and from your class pointer. Provide an explicit java method to free it when done. Besides providing the explicit method also implement a finalizer to free it as well (however that is a fail safe and should not be relied upon.) -
Is it possible to call ctx_doc.filter from Java?
Hello all,
Is it possible to call ctx_doc.filter from Java?
If so, do you have a code sample?
Thanks,
MarvinI have some Java code using ctx_doc.markup that can help:
try {
//make db conn
OracleCallableStatement stmt =(OracleCallableStatement)conn.prepareCall("begin "+
"ctx_doc.markup(index_name=>'text_idx', "+
"textkey=>?,"+
"text_query=>?,"+
"restab=>?,"+
"starttag=> '<a>',"+
"endtag=> '</a>' "+
"); " +
"end; ");
... // register other parameters
stmt.registerOutParameter(3, OracleTypes.CLOB);
stmt.execute();
oracle.sql.CLOB text_clob=null;
text_clob = ((OracleCallableStatement)stmt).getCLOB(3);
// read the CLOB by chunks
int chunk_size=text_clob.getChunkSize();
Reader char_stream = text_clob.getCharacterStream();
char[] char_array = new char[chunk_size];
for(int n=char_stream.read(char_array);n>0; n=char_stream.read(char_array)){
out.print(char_array);}
}catch (SQLException e) -
Calling ctx_doc.filter from java...is it possible?
Hello all,
Is it possible to call ctx_doc.filter from Java?
If it is possible, does anyone have a code sample they can share?
Thanks for the help,
Marvin
http://www.esenai.comI have some Java code using ctx_doc.markup that can help:
try {
//make db conn
OracleCallableStatement stmt =(OracleCallableStatement)conn.prepareCall("begin "+
"ctx_doc.markup(index_name=>'text_idx', "+
"textkey=>?,"+
"text_query=>?,"+
"restab=>?,"+
"starttag=> '<a>',"+
"endtag=> '</a>' "+
"); " +
"end; ");
... // register other parameters
stmt.registerOutParameter(3, OracleTypes.CLOB);
stmt.execute();
oracle.sql.CLOB text_clob=null;
text_clob = ((OracleCallableStatement)stmt).getCLOB(3);
// read the CLOB by chunks
int chunk_size=text_clob.getChunkSize();
Reader char_stream = text_clob.getCharacterStream();
char[] char_array = new char[chunk_size];
for(int n=char_stream.read(char_array);n>0; n=char_stream.read(char_array)){
out.print(char_array);}
}catch (SQLException e) -
Can I call an interface from java
Dear All,
Can I call an interface from java in ODI ?
Best Regards
ArcShort answer, Yes.
Long answer - you must create a scenario from the interface (the scenario is the "executable" code), right-mouse-button on the interface in the tree and "Generate Scenario". This can then be called using the invocation api this is documented in your <installationdirectry>/oracledi/doc/sdk/invocation. This points you at all the necessary classes etc to use. -
How can I call ora:appendToList from java snippet?
I want to assign a list of user from User Task A to User Task B, but I don't know how to call ora:appendToList from java snippet, and are there any better ways to solve this situation?
Hi Rakesh,
Thank you for your help.
For issue 1, for example, user jcooper apply a vacation, and the request goes to his manager jstein,
and jstein dispatch the task to mtwain and rsteven for parallel approval, (this is just for example, in
some case, the manager can use the reassign function), so I use simple workflow pattern for manager approval,
and parallel workflow pattern for parallel approval, but in my situation, the user for parallel approval is
uncertain, need select by manager jstein, so I want to know how to assign the user from java code to bpel process.
The following is how I solve the problem now, put the user list string in flexString1 of simple workflow task,
then allocate the array for parallel assigneeUsers, then use setVariableData assign the value, it can do the job,
but the code is awful, I want to know how to do it in some better way.
<assign name="copyPayloadFromTask">
<copy>
<from expression="ora:countNodes( 'inputVariable','task','/task:task /task:assigneeUsers')"/>
<to variable="currentLength"/>
</copy>
</assign>
<sequence>
<bpelx:exec name="Java_Embedding_2" language="Java" version="1.4"><![CDATA[
Element ele=(Element)getVariableData("inputVariable","task","/task:task/task:flexString1");
String users=ele.getNodeValue();
String[] userArray=users.split(",");
setVariableData("arrayLength",new Integer(userArray.length));
]]>
</bpelx:exec>
<while name="While_1" condition=" (bpws:getVariableData('currentLength')) < (bpws:getVariableData('arrayLength')) ">
<assign name="Assign_1">
<copy>
<from expression="ora:appendToList('inputVariable','task',' /task:task/task:assigneeUsers', string( 'test'))"/>
<to variable="oraBPMTemporaryVariable"/>
</copy>
<copy>
<from expression="ora:countNodes( 'inputVariable','task','/task:task /task:assigneeUsers')"/>
<to variable="currentLength"/>
</copy>
</assign>
</while>
<bpelx:exec name="Java_Embedding_1" language="Java" version="1.4"><![CDATA[
Element ele=(Element)getVariableData("inputVariable","task","/task:task/task:flexString1");
String users=ele.getNodeValue();
String[] userArray=users.split(",");
for(int i=0;i<userArray.length;i++){
setVariableData("inputVariable","task","/task:task/task:assigneeUsers["+(i+1)+"]",userArray);
}]]>
</bpelx:exec>
Thanks,
Ming -
Calling javaFX script from Java program
I am trying to call JavaFX script from a simple Java program. code as follows:
import java.io.*;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
public class My{
public static void main(String[] args) {
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByExtension("fx");
try {
InputStreamReader reader = new InputStreamReader(My.class.getResourceAsStream("first.fx"));
engine.eval(reader);
reader.close();
} catch (Exception e) {
e.printStackTrace();
my first.fx file code is here:
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.text.Text;
import javafx.scene.text.Font;
import javafx.scene.text.TextAlignment;
Stage {
title: "My First JavaFX Sphere"
scene: Scene {
width: 250
height: 250
content: [
Text {
font: Font { size: 24 }
x: 20, y: 90
textAlignment: TextAlignment.CENTER
content:"Welcome to \nJavaFX World"
} //Text
] // content
} // Scene
} // Stage
I am not able to run My.java. runtime error as follows:
java.lang.NullpointerException
Kindly correct me, where I am wrongI am able to call .fx file from Java. Thank you all for helping me to resolve this problem
Regards,
Ritu -
Calling C prog. from Java prog.
Hi.
I have a java GUI program as a interface. User can enter data, then java prog calls a C program and at the end the java GUI shows the returned parameters of C prog. The question is: how can I call C prog from Java GUI?
Thanks"Calling a program" is not standard terminology, so I'm not sure what you're asking.
Do you want to call a function in a DLL (most likely written in C) inside your Java code? Yes, that's JNI.
Or do you want to execute a program (which may happen to have been written in C, but the language doesn' matter) from inside you Java code? That's [Runtime.exec|http://java.sun.com/javase/6/docs/api/java/lang/Runtime.html]. -
UnsatisfiedLinkError while calling C library from Java Programm
Hi,
I am trying call C function from Java code but I am getting error.
Below is the code
package jnitest;
class HelloWorld {
private native void print();
public static void main(String[] args) {
new HelloWorld().print();
static {
System.loadLibrary("HelloWorld");
}I used following commands to compile and generate header files
$ javac -d build src/jnitest/HelloWorld.java
$ javah -d build -classpath build -jni jnitest.HelloWorldThen jnitest_HelloWorld.h was generated and I renamed it to HelloWorld.h.
I implemented HelloWorld.h in HelloWorld.c.
Below is the code for both the files
HelloWorld.h
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class jnitest_HelloWorld */
#ifndef _Included_jnitest_HelloWorld
#define _Included_jnitest_HelloWorld
#ifdef __cplusplus
extern "C" {
#endif
* Class: jnitest_HelloWorld
* Method: print
* Signature: ()V
JNIEXPORT void JNICALL Java_jnitest_HelloWorld_print
(JNIEnv *, jobject);
#ifdef __cplusplus
#endif
#endifHelloWorld.c
#include <jni.h>
#include <stdio.h>
#include "HelloWorld.h"
JNIEXPORT void JNICALL
Java_HelloWorld_print(JNIEnv *env, jobject obj)
printf("Hello World!\n");
return;
}I used following commands to generate so file
gcc -m32 -fPIC -D_REENTRANT -I/opt/jdk1.6.0_19/include -I/opt/jdk1.6.0_19/include/linux -c HelloWorld.c
gcc -m32 -shared HelloWorld.o -o libHelloWorld.soafter all the execution I get following directory struct in build directory
$ ls -R
HelloWorld.c HelloWorld.h jnitest libHelloWorld.so
./jnitest:
HelloWorld.classI am executing following command to run the program.
build$ java -D. jnitest.HelloWorldbut I am getting exception
Exception in thread "main" java.lang.UnsatisfiedLinkError: jnitest.HelloWorld.print()V
at jnitest.HelloWorld.print(Native Method)
at jnitest.HelloWorld.main(HelloWorld.java:16)I pointed LD_LIBRARY_PATH to build directory and executed
java -classpath build jnitest.HelloWorldbut I am still getting the same error.
Please help to fix the issue.
Thanks,The JNI method name in the .h file is different to that in the .c file.
Maybe you are looking for
-
When I put my sim card in it comes up with no service. But I put it into a friends one and it started to work and recieve text. I'm not sure why it's doing this and what to do to solve it. Does anyone know?
-
Hi, My moto is to install Oracle DB 10.2.0.4 but i didn't find that vesion of DB. so i installed 10.2.0.3 and now wanted to upgrade it to 10.2.0.4. Please redirect me to proper documentation or patch that will help me. Is there 10.2.0.4 setup directl
-
Songs in iTunes Matched but Won't Play... Sort Of...
I signed up for iTunes Match because I wanted to move my library of songs off my computer to save space and I was intrigued by the idea of being able to sync with the library from my iPad or even when I'm overseas. Sometimes it works well enough that
-
ABAP Query: Access variables in ABAP Program through InfoSet Query.
Hi, While generating a report using ABAP Query Tool, how can we access the variables in the ABAP Program in the InfoSet Query? Thanks in Advance!!!
-
Playing interactive swf files in instructor led class
We are putting together an instructor led online course. The problem we keep running into, is that when we import a .swf file when we do share document, the files comes up for all to see, but anybody (teachers, stuidents, facilitator) can click on a