LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 04-14-2004, 12:09 AM   #1
AMMullan
Member
 
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:

Code:
import java.io.*;
import java.util.*;
import java.lang.*;

public class getFileSeperator{
  public static void main(String[] args) {
  try{ 
    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)
    System.out.println(line);
  }catch(IOException ex) {
    System.out.println("ExeNativeCmd.execInUnix:error");
    };
  }
}
But what if I want to have a seperate argument:
i.e.

Code:
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
moeminhtun
Member
 
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
AMMullan
Member
 
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
 
  


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