interacting with a running c program

hi all..

i have a c program that i want to interact with from java, using processes the code for the

c program is like so...

#include <stdio.h>

int main()

{

char sentence[ 80 ];

char c;

int i = 0;

printf("Enter a line of text:\n" );

while( ( c = getchar() )!='\n' ){

sentence[ i++ ] = c;

}

sentence[ i ] ='\0';

puts("\nthe line you entered:" );

puts( sentence );

return 0;

}

and the code for the java program is like so

import java.util.*;

import java.io.*;

class StreamGobblerextends Thread

{

InputStream is;

String type;

OutputStream os;

StreamGobbler( InputStream is ,OutputStream os, String type)

{

this.is = is;

this.type = type;

this.os = os;

}

publicvoid run()

{

try

{

OutputStreamWriter osw =new OutputStreamWriter(os);

//BufferedWriter bw = new BufferedWriter(osw);

InputStreamReader isr =new InputStreamReader(is);

BufferedReader br =new BufferedReader(isr);

String line=null;

while ( (line = br.readLine()) !=null)

System.out.println(line);

//bw.write("tom is me");

//bw.write( "\n" );

osw.write("just testing");

osw.write("\n");

}

catch (IOException ioe)

{

ioe.printStackTrace();

}

}

}

publicclass GoodWinExec

{

publicstaticvoid main(String args[])

{

try

{

Runtime rt = Runtime.getRuntime();

Process proc = rt.exec("/home/generic-coder/programming/c/enterchar");

// any error message?

StreamGobbler errorGobbler =new

StreamGobbler(proc.getErrorStream(), proc.getOutputStream() ,"ERROR");

// any output?

StreamGobbler inputGobbler =new

StreamGobbler(proc.getInputStream(),proc.getOutputStream(),"IN");

// any output?

StreamGobbler outputGobbler =new

StreamGobbler(proc.getInputStream(), proc.getOutputStream(),"OUTPUT");

// kick them off

errorGobbler.start();

outputGobbler.start();

inputGobbler.start();

// any error?

int exitVal = proc.waitFor();

System.out.println("ExitValue: " + exitVal);

}catch (Throwable t)

{

t.printStackTrace();

}

}

}

when i run the program i dont get anything from the c program i want to run.

does anybody know what i am doing wrong?

i am new to programming using processes ....

your help will be highly acceptable ...

[4744 byte] By [generic-codera] at [2007-11-26 21:55:38]
# 1
It seems to me that you are confusing the use of JNI with Runtime.exec(). Maybe you want to write some JNI code to interact directly with the program?
TuringPesta at 2007-7-10 3:51:38 > top of Java-index,Java Essentials,New To Java...
# 2
does Runtime.exec not work with what i want to do?i dont know anything about JNI..isn't there a way to make what i want to do work?
generic-codera at 2007-7-10 3:51:38 > top of Java-index,Java Essentials,New To Java...
# 3
anybody please help....
generic-codera at 2007-7-10 3:51:38 > top of Java-index,Java Essentials,New To Java...