Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2013
    Rep Power

    Question Alternative to ProcessBuilder

    I want to run the command below in Java.

    D:\> ipconfig > test.txt

    ProcessBuilder seems to be a fine answer, but it is not.
    ProcessBuilder does not support pipe.

    I tried the code below.

    List<String> commands = new ArrayList<String>();
    ProcessBuilder processBuilder = new ProcessBuilder(commands); File("D:\\Test"));
    Process process = process = processBuilder.start();

    I expect the result where test.txt is created under the D:\\Test.
    But the file is not created.

    I want to know an alternative method.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power

    Default Re: Alternative to ProcessBuilder

    The tips in this article apply equally to processes launched using ProcessBuilder: When Runtime.exec() won't. Make sure you read all the parts.

    Also, go through these links:
    BB Code List - Java Programming Forum - Learn Java Programming

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Voorschoten, the Netherlands
    Blog Entries
    Rep Power

    Default Re: Alternative to ProcessBuilder

    No native process supports a pipe nor IO redirection; it's a shell (cmd.exe or bash or csh) that does that; you have to start a shell with your process as an argument and you have to feed all that to an exec( ... ) method.

    kind regards,

    Build a wall around Donald Trump; I'll pay for it.

Similar Threads

  1. processBuilder
    By Lund01 in forum New To Java
    Replies: 3
    Last Post: 10-11-2011, 02:07 PM
  2. Using ProcessBuilder
    By efebatistaarda in forum Advanced Java
    Replies: 4
    Last Post: 02-11-2011, 09:40 PM
  3. Using ProcessBuilder
    By akhil in forum New To Java
    Replies: 0
    Last Post: 07-21-2009, 11:12 PM
  4. Run ant scripts using ProcessBuilder
    By prsindagi in forum Advanced Java
    Replies: 6
    Last Post: 02-11-2009, 11:26 AM
  5. bug (?) in ProcessBuilder.redirectErrorStream(true);
    By gadasie in forum Advanced Java
    Replies: 3
    Last Post: 03-13-2008, 10:04 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts