Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2010
    Posts
    16
    Rep Power
    0

    Exclamation Problem while redirecting script output to a file using java

    Hi All ,

    I was trying to execute a unix shell script and redirect the output to a file in unix machine. When i execute the below command it is working fine


    /root/umdhanas/New/hello.sh >> big.txt

    But when i try to do the same using java program as below:

    Runtime run=Runtime.getRuntime();
    Process proc=run.exec("/root/umdhanas/New/hello.sh >> big.txt");

    A file by the name big.txt does not get created and redirection does not happen . Please help me how to solve this

  2. #2
    Join Date
    Sep 2010
    Posts
    16
    Rep Power
    0

    Default Please help on how to get the process id also

    Also please let me know how to get the process id of the script executed from java

  3. #3
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    It is important to bear in mind that exec() does not interpret its string argument the same way a bash or other shell would. See, for example, the section "Runtime.exec() is not a command line" on page 4 of this JavaWorld article.

  4. #4
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,438
    Rep Power
    18

    Default

    And that article also, conveniently, tells you how to mimic this...if I remember correctly.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

Similar Threads

  1. Replies: 9
    Last Post: 01-23-2014, 07:17 PM
  2. Problem with calling php script from java file
    By eldushyant in forum Advanced Java
    Replies: 1
    Last Post: 04-28-2010, 12:56 PM
  3. problem with output of jar file
    By nishant.4545 in forum Advanced Java
    Replies: 2
    Last Post: 07-04-2009, 04:00 PM
  4. Redirecting output at Thread level
    By beezerbutt in forum Advanced Java
    Replies: 8
    Last Post: 02-14-2009, 11:19 PM
  5. Problem creating a Post script file
    By krishnan.1000 in forum New To Java
    Replies: 0
    Last Post: 02-14-2008, 07:15 PM

Posting Permissions

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