简体   繁体   中英

using runtime.exec() in java language to execute a C file

I am writing a program in java and at a certain point, i want to execute a program in C(already written by someone else) by using the runtime.exec() method.

The program in C takes two parameters as input and gives one as output. So when i run it in the terminal i write (/the name of the exec file/) param1 param2 result

The program uses the two parameters to calculate the result. More specifically: param1 and param2 are images and somehow "compares"/"combines" them and creates a new clear image(bmp file) naming it result, it's for medical images and biomedical purposes. I didn't write the code for this program and its complicated so i want to execute it through java. If i can do that i dont have to understand how the program in C works. All i have to do is find out how to execute it by running my java program.

Can i use the runtime.exec() method in java to execute the (unfamiliar to me) program written in C.

If yes, i would also like to know how to give inputs(param1 and param2) and also how to get the output(result) for further use in my java code.

Yes, you can run any executable this way and also pass command line parameters. It does not matter at all in which language the program has been written in.

The result is not really an output but the name of the output file which you also have to provide in your call.

So you have to write is something like:

Runtime.exec("programName image1.bmp image2.bmp result.bmp");

I am not sure what you mean by "get the output(result) for further use". If you need the image data, open the image file (you know its name) with some image parsing or processing library.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM