Executing external native processes using exec

Hi,
I am running an external process in the normal way (i.e using Runtime.exec to reutrn a process object, using process.waitfor() to wait for return code etc). However, what I need is for the external process to continue running after my java application has exitted. So far I have been unable to do this � it seems the external process is still somehow a child of my Java process.
Does anyone have any idea how to do this, or even if it is possible?
Thanks in advance!

If you detach the child process (redirect stdin, out, err) from the starting one it should be no problem. waitfor() is of course not applicable.

Similar Messages

  • How to execute external  spawned process using  java

    Hi,
    I am executing PGP from command line using java.
    For adding the public key I use Runtime object like this
    Runtime rt = Runtime.getRuntime();
    Process process = rt.exec("pgp -ka "+"d:/Mangesh/pubkey/sandy.asc "+"C:/PROGRA~1/NETWOR~1/PGPNT/keyrings/pubring.pkr");PGP is executing this but inbetween it asked for confirmation "Do you want to add public key (y/n)"
    I am providing data to process this way:
    PrintWriter pw = new PrintWriter(new OutputStreamWriter( process.getOutputStream()));
    pw.write('y');
    pw.flush();But after this their is no execution from PGP and console remains until I closed it.
    PGP is waiting for ENTER KEY
    How can I provide ENTER KEY from java
    This is right method ??? or any other options are available??
    I am awaiting for your valuable suggestions .
    Regards
    Man479

    On Windows the "enter key" consists of two characters: carriage return and a line feed (\r\n). You may have to send both. If that doesn't work, pgp is not reading the reply through stdin, only through the console, and there's no way to pass the 'y' to it through Java.

  • Executing a native process and getting the text output

    Hi,
    I have the following problem.
    When I execute a native DOS process (lets say a batch file), and
    expect some text output from this process I use the following code:
    String command = "test.bat";
    Process process = runtime.exec(command);
    BufferedReader rd = new BufferedReader(new InputStreamReader(process.getInputStream()));
    String s = new String();
    while((s = rd.readLine())!=null) {
         out.println(s + "<br/>" );
    The problem is that as long as rd.readLine() does not return null, the page does not display the result. When the process crash, sometimes nothing return.
    I would like to display the output as it comes, i.e. line by line.
    I have no clue on how to do that except writting the output in a text file, and reading the text file with a page that reload every x seconds.
    I do not beleive this is a good solution.
    Additionaly, I may have a huge output. It seems to make the process
    to hang. Is there a was to fix it.
    Could someone give me some hints.
    Regards,
    Arnaud.

    I am having the same problem...did you ever solve it?

  • Executing sequence of commands using exec

    How do I execute sequence of commads using java.lang.Runtime.exec()?
    As a part of an assignment, I need to use the exec command to
    a. change drive and then
    b. change directory and then
    c. execute some command.
    Thanks.

    windows
    "pushd <dir path> && <some command>"

  • Error when executing external workflow process

    OWB 9.2 with server on Windows NT.
    I can successfully execute a mapping workflow process from the deployment manager, but I get an error when executing a simple external process:
    command: move
    parameters: ?c:\\data\\owbtest\\src.txt?c:\\data\\owbtest\\trg.txt
    Resulting output:
    Create Process: move c:\data\owbtest\src.txt c:\data\owbtest\trg.txt error=2
    File c:\data\owbtest\src.txt exists.
    My questions:
    1. What am I doing wrong?
    2. What does error=2 mean? Is this a Windows error?
    3. Do I have to configure some location for the process? What does 'use default location' mean for the configuration property Working Location? Is a host-logon performed before the host-command is executed?
    4. Is there logging available for an external process? In the workflow tables or views?
    5. I can't find much documentation for these questions. Is there more documentation than the OWB user guide and the OWF guide?
    Jaap.

    It seems that commands that are not an executable in some directory, but are part of the Windows kernel (like 'move'), need to be started as a parameter of the cmd command. I did this and now it works fine.

  • Executing a native process. Help!!!!

    Below is a program that attempts to execute DOS (or UNIX) commands (actually, I wanted to get the value of an environment variable). I got this program from another web page but I can't make it run correctly. As you can see, I made various attempts. Every time I get the message: "ex=Java.lang.IllegalArgumentException: Malformed \uxxx encoding."
    I hope you can point my nose to the problem.
    Thanks for your help.
    import java.lang.*;
    import java.util.*;
    public class EnvTest {
    public static void main( String[] args ) {
    Properties prop;
    Process process;
    try {
    String [] cmd1 = {"command", "/c", "set"};
    System.out.println("Executing command...");
    // process = Runtime.getRuntime().exec(cmd1);
    // process = Runtime.getRuntime().exec("command /c set");
    // process = Runtime.getRuntime().exec("set");
    process = Runtime.getRuntime().exec("dir");
    System.out.println("Command succeeded...");
    prop = new Properties();
    System.out.println("Got properties...");
    prop.load( process.getInputStream());
    System.out.println("system.root: " + prop.getProperty("SystemRoot"));
    catch(Exception e) {
    try {
    String [] cmd2 = {"cmd", "/c", "set"};
    process = Runtime.getRuntime().exec(cmd2);
    prop = new Properties();
    prop.load( process.getInputStream());
    System.out.println("system.root: " + prop.getProperty("SystemRoot"));
    catch(Exception ex) {
    System.out.println("ex="+ex);

    Here is a simpler version. Please take a look at the sections  and [output][output].
    Thanks.
    import java.lang.*;
    import java.util.*;
    public class EnvTest {
      public static void main( String[] args ) {
        Properties prop;
        Process process;
        try {
          String [] cmd1 = {"cmd", "/c", "set"};
          System.out.println("Executing command...");
    //      process = Runtime.getRuntime().exec(cmd1);
    //      process = Runtime.getRuntime().exec("cmd /c set");
          process = Runtime.getRuntime().exec("set");
          System.out.println("Command succeeded...");
          prop = new Properties();
          System.out.println("Got properties...");
          prop.load( process.getInputStream());
          System.out.println("system.root: " + prop.getProperty("SystemRoot"));
        catch(Exception ex) {
          ex.printStackTrace();
    }[output]
    Executing command...
    java.io.IOException: CreateProcess: set error=2
    at java.lang.Win32Process.create(Native Method)
    at ...
    at EnvTest.main(envtest.java.12)
    [output]

  • Runtime.getRuntime().exec() - native process

    Hi,
    I want to start a native (openFt) program from within my servlet. Therefore, I use Runtime.getRuntime().exec(String [] cmd). This works fine in my local OC4J container: the process is terminated with error code 0 and the native program is executed. The only strange thing here is that the output text isn't in my InputStream but in my ErrorStream.
    The real problem arises when I deploy the same Ear on the 9ias server. Here, the process doesn't execute my native command, terminates with error code 128 and leaves no inputStream and no errorStream.
    Errorcode 128 means that there are no child processes to wait for. (i call process.waitFor() to obtain the error code). I think this means my process isn't even started.
    Anyone familiar with processes in OC4J & 9IAS?
    Thanx in advance

    I guess your implementation of matchIp() is wrong:
    public class ReaderTest {
        public static void main(String[] args) {
            new ReaderTest().testReaderMethod();
        private void testReaderMethod() {
            ByteArrayInputStream dummyStrem = new ByteArrayInputStream(
                    ("*******************************************\n"
                            + "*   My shell Application                   *\n"
                            + "\n"
                            + "*******************************************\n"
                            + "\n" + " \n" + "\n" + "HELP: h\n" + "\n"
                            + "COMMAND: c\n" + "\n" + "QUIT:q\n" + "\n"
                            + "135.19.45.18> ").getBytes());
            System.out.println(readUntilIpMatch(dummyStrem));
        private StringBuilder buffer = new StringBuilder();
        protected String readUntilIpMatch(final InputStream in) {
            while (true) {
                try {
                    if (in.available() > 0) {
                        buffer.append((char) in.read());
                        Pattern pattern = Pattern
                                .compile("\\d{1,3}(\\.\\d{1,3}){3}(?=\\D)");
                        Matcher matcher = pattern.matcher(buffer);
                        if (matcher.find()) {
                            return matcher.group();
                } catch (final IOException e) {
                    throw new RuntimeException(
                            "Failed to read buffer in while looking for prompt!", e);
        } // runs forever if not matching!!!!
    bye
    TPD

  • Executing subprocess using exec method

    I want to run an exe file which is made in C and which accepts command line arguments. For this i m first getting runtime instance and then calling exec() method with name of the file to be executed and arguments i.e. command line arguments which it is accepting. But i m not able to run that exe file. I m getting IllegalThreadStateExeception. When i m running an exe file which is not accepting any command line arguments i m able to run that exe file and obtained the o/p also using getInputStream method of Runtime.
    Please tell me how to run an exe file made in C which accepts command line args.

    Runtime rt= Runtime.getRuntime();
    String[] cmd= new String[4];
    cmd[0]= "*.exe";
    cmd[1]= "arg1";
    cmd[2]= "arg2";
    cmd[3]= "argn";
    String[] env= new String[1];
    env[0]= "path" // such as c:\myfolder
    Process process= rt.exec(cmd, env, workingDir);

  • Executing external processes

    I am trying to execute a .reg file using java. I go about it like so:
    p=r.exec("cmd.exe /c "+MyReg+"");where these are the variables being used:
    Process p;
    Runtime r=Runtime.getRuntime();
    final String Home=System.getProperty("user.home");
    final String MyRoot=Home+"\\CCRecords";
    final String MyReg=MyRoot+"\\enaoroc.reg";This is all that is needed to make it execute, correct? If not, what am I missing? If so, why wouldn't it work?

    You are missing an elementary debugging step. Your code should look like this:String cmd = "cmd.exe /c "+MyReg; // adding an empty string does nothing
    System.out.println(cmd);
    p=r.exec(cmd);You ask us to tell you why your command doesn't work without even telling us what the command is. And you don't know either. If you saw the command you might immediately notice the problem, or you could try pasting it into the command line and see what happens.

  • Executing DLLs from Java using JNI vs Runtime.exec()

    I am trying to understand the best way to execute a dll using java. The dll I am testing with takes a few input parameter. If I use JNI with System.loadLibrary("dll"); what do I need to do to pass the arguements in as well? Can I just add the arguements in the java code like private int xyz = "value"; and expect that the dll will accept them or is there special definitions I have to set up in the dll to make it work?
    Alternatively I was looking at using Runtime to execute the dll by using Runtime.exec("dll param1 param2",env,filePath); Does anyone know if there are drawback to doing it this way vs. using JNI or is this just as efficient? Any help would be appreciated.

    You seem to be confused...
    "execute a dll using java"
    Unless I'm mistaken, a dll is not executable. A dll is a library of code. This code has (hopefully) some well-defined entry points (declared in a header file somewhere) which you must call in a C/C++ file. The arguments you pass to the dll will come from java through JNI.
    As far as your understanding of this entire process, it is obviously confused beyond the scope of a simple reply. I recommend you read the examples and ALL of the documentation available here:
    http://java.sun.com/docs/books/tutorial/native1.1/index.html
    When you get the/an example running (or just set up to run) then post your code and comments here for more help.
    Ian

  • Re: Error while Execute External Operating System Command using T.code SM49

    Dear Experts,
    I Have uploaded one .exe file in the application server (eg: sum.exe) and created the OS command in SM69 transaction .
    And maintained the application server path in the 'operating system command' field in SM69 t.code.
    Our SAP system, oprating system is UNIX.
    After I have executed the external command using transaction SM49 , but I got the below error.
    Can not execute external program (permission denied) , External program terminated with exit code 1
    Immediately I run the SU53 transaction code to check the authorization, but Authorization was successful.
    Could any one please help on this error.
    Thanks in advance.

    >>Can not execute external program (permission denied) , External program terminated with exit code 1
    You need to give the permission as 755 to your file.
    >>I Have uploaded one .exe file in the application server (eg: sum.exe)
    You are on UNIX and do not expect to any result of .exe file as UNIX doesn't know about this.

  • Spawn a java process using runtime.exec() method

    Hi,
    This is my first post in this forum. I have a small problem. I am trying to spawn a java process using Runtime.getRuntime().exec() method in Solaris. However, there is no result in this check the follwoing program.
    /* Program Starts here */
    import java.io.*;
    public class Test {
    public static void main(String args[]) {
    String cmd[] = {"java", "-version"};
    Runtime runtime = Runtime.getRuntime();
    try{
    Process proc = runtime.exec(cmd);
    }catch(Exception ioException){
    ioException.printStackTrace();
    /* Program ends here */
    There is neither any exception nor any result.
    The result I am expecting is it should print the following:
    java version "1.4.0"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
    Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)
    Please help me out in this regard
    Thanks in advance
    Chotu.

    Yes your right. It is proc.getInputStream() or proc.getErrorStream(). That is what I get for trying to use my memory instead of looking it up. Though hopefully the OP would have seen the return type of the other methods and figured it out.

  • How to use NAtive process with WriteUTF()?

    pls provide example NAtive process with WriteUTF() method with example.
    i wanto  call my  .js file
    "#import /D/Sunil/Flex_WorkSpace/YSIPrototype/bin-debug/data/PSAction/FinishLayoutToPhotoshop.js'; &quot;;

    Hi Sunil,
    You'll probably get better answers to this over in the Using Flash Builder forum:
    http://forums.adobe.com/community/flash_builder/using_flash_builder?view=discussions
    -Chris

  • Action profile using External communication processing type

    Hi
    I am using external communication processing type for PDF.I want to print the form instead of mail.
    Can anyone give me what's the difference if we need to only print it and not send to email. Also how can we allow the option to reprint when we need it.
    Regards,
    Deepthi.

    Hi Deepthi,
    If you want to print the PDF, you have to use procssing type as "Smart form print".
    Ex:
    with this you can print the manually multiple times also.
    Regards

  • To execute external command using   RFC_REMOTE_exec

    Hi
    i want to execute the ext command using RFC_REMOTE_EXEC .
    i have used like below in WINDOWS XP:
    data: v_cmnd(120) type C VALUE 'dir C:\SAP\rfcsdk\bin >RFEXEC -D ESM_R'.
    call function 'RFC_REMOTE_EXEC' destination D_DESTI
    exporting
    command = v_cmnd
    exceptions
    system_failure = 1 message D_ERMSG
    communication_failure = 2 message D_ERMSG.
    manually at command line the program getting registerd but
    not throuergh RFC_REMOTE_EXEC 
    in v_cmnd  what is the exact value we have to give
    Regards

    you create the command in SM69 with some name and Directly give the Same name when you are executing.
    Check this Function also.
    SXPG_COMMAND_EXECUTE

Maybe you are looking for