Results 1 to 5 of 5

Thread: exec() problem on Linux

  1. #1
    Join Date
    Mar 2010
    Posts
    203

    exec() problem on Linux

    Hello,
    I have a command that works very well when I call via the shell, but that does not work when I call from a Java program via the exec () method of Runtime.
    Here is the code for it
    Code:
    System.out.System.out.println("/ usr / sbin /...... \"" + + File "/ tcpot\" -T pdml> \""	+ + File "/ some.xml\""");
    
    Process p = r.exec ( "/ usr / sbin /....... \"" + + File "/ tcpot\" -T pdml> \""	+ + File "/ some.xml\"");
    When I execute the shell that gives me the System.out.println AC works but the call to exec is not working. How can I make that work. If you have any idea then please let me know, I am interested in it. Thanks in advance.

  2. #2
    Join Date
    Dec 2009
    Posts
    204

    Re: exec() problem on Linux

    Hello,
    I would be very grateful if someone could give me a "ready made" (if it did not take too long). If I do that, it should work?
    This is what I have tried so for, but does not work
    Code:
      Shell s = new Shell();
      String str = s.command("ls | sort").AsString();
    By cons I am unable to install the package, if you know how to do this then please help me. Thanks in advance.
    Last edited by Ash maker; 10-03-2010 at 12:55 PM.

  3. #3
    Join Date
    Nov 2009
    Posts
    583

    Re: exec() problem on Linux

    Hello,
    The simplest is that you create a shell script that accepts one argument "file"
    and you run this script from java passing it the folder you want.
    Your script will be:
    Code:
    #! / bin / bash
    / usr / sbin / ......./ TcpdumpOutput-T pdml> $1/ some.xml
    I suggest this because you're press if there was any way to do everything in java but it's longer and more complicated. I hope this will help you.

  4. #4
    Join Date
    Nov 2009
    Posts
    347

    Re: exec() problem on Linux

    Hello,
    Yes I completely agree with the above post and I would like to add some more points to it. The function will just run this script from your java code and wait for the end:
    Code:
    String fl = "/ home / Jaggy / moDossier";
    String cmd[] = { "myshell.sh", fl };
    Process prc = runtime.exec(cmd);
    prc.getInputStream.close();
    prc.getErrorStream.close();
    prc.getOutputStream.close();
    prc.waitfor();
    Hope this will help you.

  5. #5
    Join Date
    Dec 2009
    Posts
    192

    Re: exec() problem on Linux

    Hello,
    I do not know this is what you want, but see if this helps you
    Code:
    String [] c = new String [] {
     "java","-jar","myjar.jar"
    };
    Runtime.getRuntime().exec(c);
    Hope this will help you.

Similar Threads

  1. PHP Exec() Wait Time
    By InterNetWorKed in forum Software Development
    Replies: 7
    Last Post: 13-05-2010, 12:14 PM
  2. exec() function in java
    By Lauren Ambrose in forum Software Development
    Replies: 5
    Last Post: 11-03-2010, 11:23 AM
  3. How to disable exec() function in PHP
    By Japheth in forum Software Development
    Replies: 3
    Last Post: 04-05-2009, 09:38 AM
  4. Backup Exec Error
    By Jarhead69 in forum Networking & Security
    Replies: 5
    Last Post: 27-03-2009, 03:14 PM
  5. o2 XDA Exec
    By Mastermind in forum Reviews
    Replies: 4
    Last Post: 23-06-2007, 03:52 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,508,614.01850 seconds with 17 queries