LinuxQuestions.org
Visit Jeremy's Blog.
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 06-17-2009, 11:30 AM   #1
abd_bela
Member
 
Registered: Dec 2002
Location: algeria
Distribution: redhat 7.3, debian lenny
Posts: 620

Rep: Reputation: 31
external command in java


hi,
how to execute an external program from java.

the equivalent to the system C command : system( thecommand ), where command is any unix command or program like ls, gedit or firefox
I am working on debian

thanks for help
bela
 
Old 06-17-2009, 11:45 AM   #2
noctilucent
Member
 
Registered: Jun 2009
Distribution: slackware
Posts: 123

Rep: Reputation: 34
system() is bad, m'kay? java.lang.runtime.exec
 
Old 06-17-2009, 11:47 AM   #3
indienick
Senior Member
 
Registered: Dec 2005
Location: London, ON, Canada
Distribution: Arch, Ubuntu, Slackware, OpenBSD, FreeBSD
Posts: 1,853

Rep: Reputation: 65
The exec() function is overloaded - see here for details.

A simple example:
Code:
public class SystemCall {

  static public void main(String[] args) {

    Runtime.getRuntime().exec("gedit");

  }

}
EDIT: noctilucent, I agree with you, but sometimes, you just gotta use it.

Last edited by indienick; 06-17-2009 at 11:49 AM.
 
Old 06-17-2009, 04:38 PM   #4
Witi
LQ Newbie
 
Registered: Oct 2008
Location: Cologne, Germany
Distribution: Gentoo
Posts: 6

Rep: Reputation: 0
Since Java 1.5 there is also a ProcessBuilder class.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
how to add external jars, Java program with Reference Libraries yuubouna Linux - Newbie 3 11-30-2008 10:19 PM
Remove external script execution in C, C++ and Java Sinedie Linux - Security 15 08-24-2008 08:35 PM
java -version, bash: java: command not found kirman Programming 4 03-20-2008 12:13 AM
Help Please. dd command to external device DuncanL Linux - Newbie 2 11-01-2007 05:38 AM
java command - "bash: java: command not found" ??? RedHat123 Programming 2 07-17-2002 12:09 AM

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

All times are GMT -5. The time now is 04:24 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration