LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-15-2004, 12:48 PM   #1
ambuj
LQ Newbie
 
Registered: Nov 2003
Posts: 10

Rep: Reputation: 0
Question how will i run a exe from java code?


How will i run an executable file(exe) from my java or c++ code? With some paremeters.....and i also want to get the responce back from this exe..like some integer....
can anyone help me out?
 
Old 01-15-2004, 02:05 PM   #2
synna
Member
 
Registered: Jan 2004
Posts: 40

Rep: Reputation: 15
You can execute any program you want like this

Process p=Runtime.getRuntime().exec(your command line).

then you can redirect the output of Process where you want with p.getOutputStream() and so on (you can also get the InputStream)

check Java documentation on Runtime and Process for more
 
Old 01-24-2004, 02:16 AM   #3
ambuj
LQ Newbie
 
Registered: Nov 2003
Posts: 10

Original Poster
Rep: Reputation: 0
tell me more

Please tell me more about this........

give me a run able code if possible.......
thanks.
 
Old 01-24-2004, 06:23 AM   #4
Looking_Lost
Senior Member
 
Registered: Apr 2003
Location: Eire
Distribution: Slackware 12.0, OpenSuse 10.3
Posts: 1,120

Rep: Reputation: 45
a quick example catching the output from ls -l your home directory

Code:
import java.io.*;


public class Running
{
 public static void main(String args[])
 {

  Runtime rTime=Runtime.getRuntime();

  String output;


 try
 {

   Process  rProcess=rTime.exec("ls -l " +  System.getProperty("user.home"));

   BufferedReader   bufRead=new BufferedReader (new    InputStreamReader(rProcess.getInputStream()));

   while( (output=bufRead.readLine())!=null)
      {
        System.out.println(output);
        }

  }catch(IOException ioe)
       {
        System.err.println(ioe);
        System.exit(1);
        }

  }

}
 
Old 01-24-2004, 07:28 AM   #5
ambuj
LQ Newbie
 
Registered: Nov 2003
Posts: 10

Original Poster
Rep: Reputation: 0
more help........

thanks for the help....

but i want to call the executable file with two parameters........can anybody help me out for this.......?

Thank you.
 
Old 01-24-2004, 08:27 AM   #6
llama_meme
Member
 
Registered: Nov 2001
Location: London, England
Distribution: Gentoo, FreeBSD
Posts: 590

Rep: Reputation: 30
That example passed one parameter to the 'ls' command (the -l option), so use your imagination to see how you could pass two

Alex
 
Old 01-24-2004, 08:32 AM   #7
ambuj
LQ Newbie
 
Registered: Nov 2003
Posts: 10

Original Poster
Rep: Reputation: 0
Cool thanks

Thanks.....the code is working fine now....
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
C: Disabled - Cannot run .exe gibran SUSE / openSUSE 2 10-03-2005 09:22 AM
run a .exe file kuertensun Debian 6 07-01-2005 11:01 AM
getting the source code out of a .exe purefan Programming 4 03-05-2005 12:19 PM
How to run a exe file? solutionseeker Linux - Newbie 7 01-28-2005 01:51 AM
Run exe in Linux???!!!!! yenonn Linux - General 10 10-14-2004 06:48 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:49 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration