Welcome to the most active Linux Forum on the web.
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 04-14-2004, 12:09 AM   #1
Registered: Sep 2003
Location: United Kingdom
Distribution: Ubuntu, Arch
Posts: 437

Rep: Reputation: 30
system calls in Java

Hey all

I want to be able to use system calls in Linux using Java - I know you can use something like the following:

import java.util.*;
import java.lang.*;

public class getFileSeperator{
  public static void main(String[] args) {
    Runtime aRT = Runtime.getRuntime(); //Runtime.getRuntime();
    //Spawn a shell sub-process
    Process aProc = aRT.exec("//sbin//ifconfig -a");
    BufferedReader kbdInput = new BufferedReader(new InputStreamReader(aProc.getInputStream()));
    String line;
    while((line = kbdInput.readLine()) !=null)
  }catch(IOException ex) {
But what if I want to have a seperate argument:

String arg1 = "-a";
String arg2 = "eth0;

Process aProc = aRT.exec("//sbin//ifconfig" + arg1);
This doesn't seem to work for me
Old 04-14-2004, 01:02 AM   #2
Registered: Dec 2002
Location: Singapore
Distribution: Fedora Core 6
Posts: 647

Rep: Reputation: 30
You didn't put space after "ifconfig" in your code,

Process aProc = aRT.exec("//sbin//ifconfig " + arg1); //put space
Old 04-14-2004, 01:48 AM   #3
Registered: Sep 2003
Location: United Kingdom
Distribution: Ubuntu, Arch
Posts: 437

Original Poster
Rep: Reputation: 30
Thanks heaps moeminhtun Worked perfectly...

Been doing Java Development for a few days now, still noobish but it's heaps of fun


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
shell example using system calls djgerbavore Programming 7 03-06-2010 02:39 AM
Making system calls in C++ harisund Programming 4 11-26-2005 05:58 PM
Some system calls Spooky Programming 1 11-24-2004 10:17 AM
java and system calls aizkorri Programming 6 06-20-2003 01:54 AM
Number of system calls vladmihaisima Linux - General 2 10-02-2002 02:36 PM

All times are GMT -5. The time now is 05:04 PM.

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 @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration