Share your knowledge at the LQ Wiki.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 06-17-2009, 10:30 AM   #1
Registered: Dec 2002
Location: algeria
Distribution: redhat 7.3, debian lenny
Posts: 620

Rep: Reputation: 31
external command in java

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
Old 06-17-2009, 10:45 AM   #2
Registered: Jun 2009
Distribution: slackware
Posts: 123

Rep: Reputation: 34
system() is bad, m'kay? java.lang.runtime.exec
Old 06-17-2009, 10:47 AM   #3
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:
public class SystemCall {

  static public void main(String[] args) {



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

Last edited by indienick; 06-17-2009 at 10:49 AM.
Old 06-17-2009, 03:38 PM   #4
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.


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 09:19 PM
Remove external script execution in C, C++ and Java Sinedie Linux - Security 15 08-24-2008 07:35 PM
java -version, bash: java: command not found kirman Programming 4 03-19-2008 11:13 PM
Help Please. dd command to external device DuncanL Linux - Newbie 2 11-01-2007 04:38 AM
java command - "bash: java: command not found" ??? RedHat123 Programming 2 07-16-2002 11:09 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:32 AM.

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