Problem running Runtime.exec()

unable to run c compiled code from java

Page 1 of 1

7 Replies - 1728 Views - Last Post: 01 January 2010 - 02:14 PM Rate Topic: -----

#1 sara12345  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 26-December 09

Problem running Runtime.exec()

Posted 26 December 2009 - 01:09 PM

hello everyone
I hope that someone can help me
I have tried to run c code in java using Runtime but I got the following error:
Debug assertion failed
file:fprintf
line:56
althogh the c code is working correctly using visual c++ 6.0 and does not generate error and I'm able to run it using dll but I'm unable to run it using java

Hlppppppppppppppp please
thanks in advance

*Edited: topic title changed... it misleaded a few :)

This post has been edited by pbl: 26 December 2009 - 04:59 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Problem running Runtime.exec()

#2 erik.price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 485
  • View blog
  • Posts: 2,690
  • Joined: 18-December 08

Re: Problem running Runtime.exec()

Posted 26 December 2009 - 01:17 PM

Could you post code relevant to the problem using the code tags?

Thank you.

:code:
Was This Post Helpful? 0
  • +
  • -

#3 skaoth  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 91
  • View blog
  • Posts: 601
  • Joined: 07-November 07

Re: Problem running Runtime.exec()

Posted 26 December 2009 - 04:30 PM

You can't call C/C++ code directly from java.

You have to use JNI
http://java.sun.com/...tml/jniTOC.html

or JNA. (This wraps some of the ugliness that is JNI)
https://jna.dev.java.net/
Was This Post Helpful? 0
  • +
  • -

#4 Dogstopper  Icon User is online

  • The Ninjaducky
  • member icon



Reputation: 2871
  • View blog
  • Posts: 11,026
  • Joined: 15-July 08

Re: Problem running Runtime.exec()

Posted 26 December 2009 - 04:35 PM

Like skaoth said, you can't call RAW C code from java without those interfaces, but you can run COMPILED executables from Java using the method that you described above.
Was This Post Helpful? 0
  • +
  • -

#5 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8328
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Problem running Runtime.exec()

Posted 26 December 2009 - 04:56 PM

Please folks read posting carefully... if you do not understand them to not reply
He is not running C code from Java
He is running a .exe from Runtime.exec()
Was This Post Helpful? 0
  • +
  • -

#6 sara12345  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 26-December 09

Re: Problem running Runtime.exec()

Posted 01 January 2010 - 01:50 PM

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();


Was This Post Helpful? 0
  • +
  • -

#7 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2687
  • View blog
  • Posts: 11,349
  • Joined: 20-September 08

Re: Problem running Runtime.exec()

Posted 01 January 2010 - 02:13 PM

http://www.javaworld...1229-traps.html

Read the above carefully
Was This Post Helpful? 0
  • +
  • -

#8 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8328
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Problem running Runtime.exec()

Posted 01 January 2010 - 02:14 PM

Skaoth already answered
Topics merged
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1