Results 1 to 11 of 11
- 01-01-2010, 07:56 PM #1
Member
- Join Date
- Dec 2009
- Posts
- 59
- Rep Power
- 0
calling c program from java. hlp please
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 the c program the console 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 console so please can you tell me the problem
I have used the following code to call c from java:
Java Code: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();
- 01-01-2010, 08:09 PM #2
Member
- Join Date
- Dec 2009
- Posts
- 59
- Rep Power
- 0
I have said the console sorry it is not console it must take the input file name from the black screen when I press application file
- 01-02-2010, 03:49 AM #3
Senior Member
- Join Date
- Nov 2009
- Posts
- 235
- Rep Power
- 4
When you run it, do you see another console pop up, I'm not sure what you are trying to accomplish. Please explain better.
- 01-02-2010, 07:48 AM #4
Member
- Join Date
- Dec 2009
- Posts
- 59
- Rep Power
- 0
no I didn't see any console except java console. I'm trying to call whole c program in java. the c program must take input file name in the black screen and must return output file. when I run java using the above code I didn't see any black screen how can I enter the input file name???
can you please tell me what is the problem????
thanks
- 01-02-2010, 10:03 AM #5
Senior Member
- Join Date
- Nov 2009
- Posts
- 235
- Rep Power
- 4
I think what you are saying is that you run the java from a console and it produces the output of the c program, but you cannot input anything. If that is correct the problem is that you do not get the c programs Output Stream, only the InputStream. What you can do is use a Scanner of system.in on your java program and send that to the c exe via a bufferedWriter of p.getOutputSteam()
- 01-02-2010, 10:20 AM #6
Member
- Join Date
- Dec 2009
- Posts
- 59
- Rep Power
- 0
no. the c program must works as follows:
it must take an input file from black screeen and it must return output file.
when I call c program from java I didn't get any thing. the black screen doesn't appear to take input file and also there is no output file I don't know why
although I have run c program from visual c++ it runs fine and also I have run it from command prompt and it works but I don't know what is the problem with java
-
You can hook onto both the C program's (executable program) standard input and output stream from your Java program, just do it in two different threads so one doesn't block the other: Java Programming [Archive] - standard input into a different process
as Collin already has suggested.
- 01-02-2010, 04:52 PM #8
Member
- Join Date
- Dec 2009
- Posts
- 59
- Rep Power
- 0
thanks for the reply but it also doesn't work I mean the command line must be appeared so that I can enter the input file name and then it produces output file
but I didn't get any thing
I have write
can you tell me what is wrong ??Java Code:Runtime rt = Runtime.getRuntime(); Process proc = rt.exec("cp1.exe"); OutputStream os = proc.getOutputStream(); DataOutputStream dos = new DataOutputStream(os); dos.writeUTF("s"); os.close();
- 01-03-2010, 05:43 PM #9
Member
- Join Date
- Sep 2009
- Posts
- 37
- Rep Power
- 0
Hi.
Please refer to the url below:
Calling C Code from Java
Regards,
raqman.Last edited by raqman; 01-03-2010 at 05:50 PM.
RAQ Report: free Java reporting tool.
- 01-19-2010, 11:27 AM #10
Member
- Join Date
- Jan 2010
- Posts
- 4
- Rep Power
- 0
how can i call a c++ program in java??
anyone have idea?
i tried but have a linking error
- 01-19-2010, 11:35 AM #11
Member
- Join Date
- Jan 2010
- Posts
- 4
- Rep Power
- 0
how call a c++ progaram in java
i hava a java progaram
class HelloWorld {
public native void displayHelloWorld();
static {
System.loadLibrary("hello");
}
public static void main(String[] args) {
System.out.println("\n Hey now calling display method\n");
new HelloWorld().displayHelloWorld();
}
}
also a c program
#include<jni.h>
#include"HelloWorld.h"
#include<stdlib.h>
#include<iostream.h>
#include<conio.h>
JNIEXPORT void JNICALL
Java_HelloWorld_displayHelloWorld(JNIEnv *env, jobject obj)
{
printf("\n Hello compiling C file !!!! \n " );
return;
}
using as
java helloworld.java
javah -jni helloworld
gcc -I c:\jdk\include -g -c helloworldImp.c -o libhello.so
but this gave many errors in jni.h
how can it be used pls tell me ........
thanks in advance...
;)
Similar Threads
-
urgent:calling c program from java
By rach in forum New To JavaReplies: 6Last Post: 01-19-2010, 11:37 AM -
help calling 1 .java from another.
By New-to-this in forum New To JavaReplies: 1Last Post: 08-14-2009, 04:22 AM -
Calling a JFrame window from a command line program.
By new_2_java in forum New To JavaReplies: 7Last Post: 11-09-2008, 03:40 AM -
calling a java application from another
By kratoras in forum New To JavaReplies: 1Last Post: 06-14-2008, 02:54 AM -
Calling mainframe IMS program from Java
By babu95 in forum New To JavaReplies: 2Last Post: 12-21-2007, 01:08 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks