System calls in Java

Any suggestions how one would perform a UNIX call inside a C++ or Java program?
Student who needs help.

If it is really a system call, then you will have to define and implement a "native" method.
o java method witha "native modifier".
o write a small c program that implements the method
If you define the native method, and then run java.h, the result is a header file for the c program.

Similar Messages

  • Making system calls in java

    I want to join some split files into one. In command prompt I use COPY /B file.1+file.2 file to join the files. How can i do the same in my java application. Please show the code which I suppose will use getRuntime. Thanks in advance.

    Well if there is a problem with system calls then can
    you tell me if there is a class in java for
    concetanating files. Not directly.
    At present I am joing the files
    by reading each byte from the files and writing them
    to another file which takes hell lot of time. You should read the files in large chunks. Much much faster.
    Thanks
    in advance again. Also if you say about sequential
    file class then please expalin a bit bcs I couldn't
    implement it.Post the code you are having trouble with explaining what it should do and what it actually does.

  • Unix system() system call in Java

    Hi,
    system() call in Unix is very helpfull when you need to implement a piece of code that is already implemented in an exsiting utility.
    Is there a way to achive a similar functionality?
    To put it in simpler words - is there a way, in Java, to call some method that will invoke a Unix shell and will execute the command specified in the string that is past in?
    Could you please CC the reply to [email protected]
    Thanks,
    -Michael

    Runtime.exec()
    > Could you please CC the reply to [email protected]
    Certainly not.

  • Unix System Calls using Java

    Hi!
    Can anyone tell me how to do Unix System Calls in my Java program?
    If possible please give me the java code for it taking one unix system call as an example.
    Thanks in advance
    Raj

    do you mean firing off a shell command, or making actual kernel API calls or C library calls?
    for shell commands, have a look at Runtime.exec(). for kernel calls, use JNI. the JNI FAQ mentions something called "shared stubs" that may be of use:
    http://java.sun.com/products/jdk/faq/jnifaq.html
    cheers,
    p

  • System call fom Java code

    Hi all
    I hope someone over here might answer my problem.
    I need to run a Shell script form my Java code, which does perform some operations like writing/copying files to a specific directory and my Java code then starts reading the files and do necessary stuff like parsing it for some info inside the file.
    If I make a system call from my Java code, how do I know when the shell script is done executing completely? Just to make sure that my Java code execution starts only after the shell script has executed.
    If anyone has come across such a scenario, please reply to this topic. A sample code wud be a bonus for me :)
    Thanks
    -Uday

    If you've never used Runtime.exec, read this carefully first:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
    MOD

  • How do i make UNIX system calls in Java app?

    Is it possible to make UNIX system calls in a java app? I.E. perform a file copy/move to another machine within a program.
    Thanks,
    Erik

    If there is a command line tool then you use Runtime.exec() otherwise you have to use JNI.
    If you want to access shared libraries you might want to look at www.swig.org

  • System Call by Java Application - [change path and run of the other progra]

    public class  A {
         public static void main (String[] args)
              System.out.println("Hi");
    }I do have above A.java.
    I am generating A.class from it.
    A.class is in the following directory :
    /home/sachin/work/Sample_Directory/bin/hello_filetest/
    I have another program which makes System call.
    But the problem is B.java is in the different directory :
    /home/sachin/work/Sample_Directory/src/hello_filetest/
    public class  B {
         public static void main (String[] args) {
    Process p1 = Runtime.getRuntime().exec("java A);
                BufferedReader stdInput = new BufferedReader(new
                     InputStreamReader(p1.getInputStream()));
    while ((s = stdInput.readLine()) != null) {
                    System.out.println(s);
    {code}
            So, my question is how to change directory by system calls and execute the program
    which is lying in other directory ????
    Thank you.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    The following code will call javac on a .java file, which will compile it into a .class file
         public static void javacTest() {
              JFileChooser jf = new JFileChooser();
              if (jf.showOpenDialog(null) != jf.APPROVE_OPTION) return;
              File file = jf.getSelectedFile();
              File dir = file.getParentFile();
              try {
                   Process p = Runtime.getRuntime().exec("javac " + file.getName(), null, dir);
                   IOUtils.pipe(p.getInputStream(), System.out);
                   IOUtils.pipe(p.getErrorStream(), System.out);
              catch (IOException iox) {
                   iox.printStackTrace();
         }Is that what you're trying to do, or are you trying to run the compiled (.class) file? Running your .class file should be basically the same as the above, assuming that you are not using any non j2se libraries, except that you need to take into account the package (if package is x.y, you must have file in ...src\x\y\foo.class - call "java x.y.foo" from src)

  • Issuing Solaris system calls through Java

    How can I issue a system call to Solaris using Java? (i.e. Start a script, open a file, and similar)

    Hi Srini,
    This is just a suggestion, but try entering the following commands (in your SQL*Plus session) before executing your stored procedure:
    set serveroutput on size 1000000
    exec dbms_java.set_output(1000000)Hope this helps.
    Good Luck,
    Avi.

  • How to access system calls from java program?

    i am having a doubt regarding accessing system calls from a Java program like accessing unix system calls from a c program.

    Runtime.getRuntime().exec("line command here");
    example:
    Runtime.getRuntime().exec("ls -la");

  • System Call from Java, problem LD_LIBRARY_PATH

    I use class Runtime to invoke Operating System Call.
    I want to run OS command gpg (gnu program for encrypting/ decrypting files).
    What is interesting, when I run my sqlplus script from system user (used for database installation) call ends with success.
    Running script from other os users or machines ends with -1 code and error message:
    "ld.so.1: gpg: fatal: libiconv.so.2: open failed: No such file or directory"
    gpg uses libraries given LD_LIBRARY_PATH (/opt/gnupg/lib:/usr/lib:/usr/local/lib)
    I think that is the problem. Is there a workaround for that??
    Best regard
    Grzegorz

    Maybe related to the fact that the PATH environment variable is unset then re-initialized by Oracle to PATH = /usr/local/bin:/bin:/usr/bin. Try using absolute path for the OS commands.
    Kuassi
    - blog http://db360.blogspot.com/
    - book http://db360.blogspot.com/2006/08/oracle-database-programming-using-java_01.html

  • System Call via Java Stored Procedure?

    Within a Java stored procedure I do
    a FTP Call to a remote Server.
    The running FTP Process belongs to
    the Oracle System User (Operating System: Linux).
    Is there a possibility to run that FTP
    call with a different operating system
    user?

    another example of invoking a Java Stored Prodedure from WITHIN a PL/SQL function? What's the issue here? A java stored procedure is a java class wrapped in PL/SQL. Consequently the invocation from with PL/SQL is a straightforward PL/SQL call.
    So what is it that is troubling you?
    Cheers, APC

  • Cross platform operating system calls from Java

    For our application we need to call an external program to perform FTP. We use ncftp as it's available on all the server platforms our clients use (Sun, HP, Linux, Windows). Up to now we've been using a Java program that listens to the Oracle pipe and sends a string to the OS.
    Now we are using 8i we thought it would be better to use Java within Oracle as this should reduce problems due to the external program not running. On Windows it works fine, but on Linux runtime.exec does not seem to take account of the system path. If I send something like '/usr/bin/ncftpput ...' it works, but I can't rely on the executable being in that directory although it should be somewhere in the path. I want to just pass 'ncftpput ...'.
    Ideally I want to be able to make the code OS independent, but would consider doing something in the Java part to detect the OS and adapt accordingly, perhaps by using a shell e.g. '/bin/sh -c ncftpput ...', but I've had problems with that using the whole command line and can I rely on having a specific shell on all *nix systems?
    At some point we'd like to do all the FTP from within Oracle, but that looks like a bigger project.
    Any ideas/suggestions?
    Thanks
    Steve

    Steve,
    To determine the OS, you should be able to check the System properties. As an example, when I run this (quick and dirty) sample code, I can see that os.name=Windows NT on my Windows instance:
    CREATE OR REPLACE JAVA SOURCE NAMED "envTest" AS public class envTest {
    public static void getEnvVar() {
    System.getProperties().list(System.out);
    CREATE OR REPLACE PACKAGE envTest IS
         PROCEDURE getEnvVar;
    END;
    CREATE OR REPLACE PACKAGE BODY envTest IS
         PROCEDURE getEnvVar IS
         LANGUAGE JAVA NAME 'envTest.getEnvVar()';
    END;
    To see the output after executing envTest.getEnvVar, map System.out to DBMS_OUTPUT before running it, as follows:
    set serveroutput on
    begin
    dbms_java.set_output(100000);
    end;
    Hope this helps,
    -Dan
    http://www.compuware.com/products/devpartner/db/oracle.htm
    Debug PL/SQL and Java in the Oracle Database

  • System call in Java

    Can we make calls to programs written in other languages using java. Is it possible that we can call Unix OS commands and Utilities using Java.

    you can do that with
    Process p = Runtime.getRuntime().exec(command);
    there are many overloaded exec methods. see the api docs here.
    http://java.sun.com/j2se/1.3/docs/api/java/lang/Runtime.html
    but before you do that read this article for problems with exec and how to avoid them
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
    hth
    partha

  • System calls through Java stored Proc

    Hi,
    Aim: Execute host command from pl/sql thru java stored proc.
    1. Created a java class to take system command that could be executed.
    2. It runs fine when the class file is executed.
    3. when the java file is loaded to database to access it as java stored proc, for any valid and invalid system commands it is giving out 'PL/SQL successfully completed.
    Results were not seen.
    4. Java source file.
    import java.io.*;
    import java.lang.*;
    public class Util extends Object
    public static int RunThis(String[] args) {
    Runtime rt = Runtime.getRuntime();
    int rc = -1;
    String s = null;
    try
    Process p = rt.exec(args);
    BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
    BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
    // read the output from the command
    System.out.println("Here is the standard output of the command:\n");
    while ((s = stdInput.readLine()) != null) {
    System.out.println(s);
    // read any errors from the attempted command
    System.out.println("Here is the standard error of the command (if any):\n");
    while ((s = stdError.readLine()) != null) {
    System.out.println(s);
    System.exit(0);
    catch (Exception e){
    e.printStackTrace();
    rc = -1;
    finally {
    return rc;
    public static void main(String[] args){
    Util.RunThis(args);
    public static String exec(String args){
              Util.RunThis(args);
              return "Srini it is successful";
    5. When ran from host prompt (unix),
    executed successfully,
    $ /opt/java1.3.1/bin/java Util /usr/bin/ls -l
    Here is the standard output of the command:
    total 30862
    -rwxrwxrwx 1 xyz develope 1348218 Jan 2 17:47 02Jan03-2.zip
    -rw-r----- 1 xyz develope 21864 Jul 9 2002 109-60_2_modified7.sql
    -rw-r----- 1 xyz develope 44934 Jul 9 2002 109-60_2_modified8.sql
    Here is the standard error of the command (if any):
    xyz@xxxxx:abcd:/home/xyz
    $
    6. loadjava,
    $ loadjava -user username/password Util.java
    7. Create proc,
    SQL> create procedure echo_input(s1 varchar2) as language java name 'Util.main(java.lang.String[])';
    2 /
    Procedure created.
    8. Execute proc.
    SQL> exec echo_input('/usr/bin/ls -l');
    PL/SQL procedure successfully completed.
    SQL> exec echo_input('/home/o_report/reports/rcli_ASCT &');
    PL/SQL procedure successfully completed.
    SQL> set serverout on
    SQL> exec echo_input('/home/o_report/reports/rcli_ASCT');
    PL/SQL procedure successfully completed.
    SQL> exec echo_input('ddsafafasf');
    PL/SQL procedure successfully completed.
    TIA,
    Srini.

    Hi Srini,
    This is just a suggestion, but try entering the following commands (in your SQL*Plus session) before executing your stored procedure:
    set serveroutput on size 1000000
    exec dbms_java.set_output(1000000)Hope this helps.
    Good Luck,
    Avi.

  • How to deal with pipe in the Java system call?

    Hi, all,
    I tried to use a system call in java. The command contains a "|" pipe. It works both in perl and C if I do {color:#3366ff}system("ls -l | wc"){color}, but when I do it in Java, I didn't get anything returned. Here is the code
    {color:#3366ff}import java.io.*;
    class SystemCall{
    public static void main(String[] args) throws IOException {
    StringBuffer sb = new StringBuffer();
    Process p = Runtime.getRuntime().exec("ls -l | wc");
    BufferedReader br=new BufferedReader(new InputStreamReader(p.getInputStream()));
    String line;
    while((line=br.readLine())!=null) {
    System.out.println(line);
    }{color}
    If I use Runtime.getRuntime().exec("ls -l"), the code returns correctly. Does anyone know the solution?
    Thanks

    When you exec a process, it doesn't go through the shell. The I/O redirection symbols are interpreted and used by the shell.
    You have a few options.
    One is to not use Runtime.exec at all. You really don't need it for what you're doing -- the stuff in java.io is fine for that.
    Another is to exec multiple processes and do the redirection in Java yourself. I wouldn't recommend that, but it's an option.
    Another is to exec a shell, and pass your program to it as a shell script or as a one-line script passed on the command line.
    I'd suggest the first one in this case.
    By the way, what you're doing isn't really a "system call". You're forking and exec'ing a process (or really, multiple processes).

Maybe you are looking for

  • Unistall trial version of DW CS3 from Mac?

    What's the procedure for uninstalling the trial versions of Adobe Software. They have not put any Add or Remove icons in the Applications>Utilities>Adobe Utilities>Adobe Installers folder? Can I take it it's safe for me just to drag the folder relate

  • DeskJet 9670 on Windows 8.1.

    I have been using the above printer on Windows XP for several years, having set up from the drivers on the installation CD. I purchased a laptop running Win8.1 last July, and found that the native drivers would not install, but was advised to use the

  • Graphics2d draw rect

    i have a prog taht can make form and put it on a big panel , like a paint, but i had to make other little panel that coontain one form each because i want ti to be able to move it! now with the mouse you can drag and drop to make rectangle and you ca

  • Firewall Issue for Client Login

    I am trying to setup a mobile user between my mac mini server and MBAir (SL both). I have the user created on the server as a mobile user etc but I cant connect the MBA to the server with the firewall active. As soon as I turn off the firewall it see

  • Purchasing apple one to one with a refurbished macbook- how to purchase?

    Was told in store that I could get one to one with a refurb, and nothing in t&c says you can't but the option to buy it doesn't appear? What do I do? Thanks