Results 1 to 5 of 5
- 03-27-2012, 03:12 PM #1
Running executable through Java on linux
Hey guys,
I'm running into a likely silly issue.
I need to execture a complied c file, in my java code, and need to do it in linux (newest ubuntu distro)
Narrowing it down to an example:
C code:
and my java code running it:Java Code:#include<stdio.h> main() { printf("Hello World"); FILE *exeFile; exeFile = fopen("myFile","w+"); fclose(exeFile); }
Where exeTest is the compiled c file.Java Code:... Runtime r=Runtime.getRuntime(); Process p = null; String s ="/home/otacon/Desktop/exeTest"; p=r.exec(s); ...
Executing the file directly generates the print, and the empty file 'myFile', which is what I want. However, running it through Java (Eclipse) it runs but does absolutely nothing. At first I thought I might just not be getting the output, which is why I added the file creation, but that is not created either.
Thanks in advance for the help!
- 03-27-2012, 05:43 PM #2
Re: Running executable through Java on linux
Well, just an update, I managed to fix it for now, but only in windows,
Compiling the C code in Windows, and runningdoes the trick for now. But I still need to figure out how to accomplish this under linux.Java Code:Runtime.getRuntime().exec("C:\\exeFile");"
Thanks!--Otacon
Somebody set up us the bomb.
- 03-27-2012, 06:08 PM #3
Re: Running executable through Java on linux
OH.MY.GOD. *facepalm*
So yea, the code in my original post works just fine (linux and win). Of course the text output doesn't show up in Eclipse console, which i anticipated, but I brainfarted and didn't think that the file will be created in the Eclipse workspace, not where the compiled c file was located -_- (unlike it is when running it directly)
Way to loose 4 hours.
Sorry for wasting your time!--Otacon
Somebody set up us the bomb.
- 03-27-2012, 06:11 PM #4
Re: Running executable through Java on linux
the text output can be brought into the eclipse console by taking the process into a buffered reader.
example,
Edited to add: output will beJava Code:Process p = Runtime.getRuntime().exec("echo Hi it's me dhilip"); BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream())); String s = null; while ((s = stdInput.readLine()) != null) { System.out.println(s); }
regardsJava Code:Hi it's me dhilip
dhilipLast edited by noobplus; 03-27-2012 at 06:15 PM.
- 03-27-2012, 06:39 PM #5
Similar Threads
-
Running Executable jar
By yogi1410 in forum Advanced JavaReplies: 12Last Post: 04-21-2010, 04:46 PM -
Errors running app in linux but not in Windows
By JohnST in forum New To JavaReplies: 3Last Post: 03-12-2010, 01:58 AM -
creating executable .jar for linux, mac, and windows
By JohnST in forum New To JavaReplies: 3Last Post: 01-21-2010, 01:51 AM -
Running Linux
By selva.bics in forum AWT / SwingReplies: 1Last Post: 08-31-2009, 07:01 PM -
Running Tomcat in Linux from Eclipse.
By Felissa in forum EclipseReplies: 1Last Post: 06-05-2007, 05:47 AM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks