Results 1 to 2 of 2
  1. #1
    Basit56 is offline Member
    Join Date
    Aug 2009
    Rep Power

    Default problem in executing linux command

    Hope you all will be fine. I used this code to run Linux command and it worked fine.

    Java Code:
     Process myProcess = Runtime.getRuntime().exec("chmod 755 //test//msg0000.wav" );
    But now i want to run the same command with the different path. The problem is one of the path parameter i am getting from the method. So the problem is, how i write the path

    Java Code:
    Process myProcess = Runtime.getRuntime().exec("chmod 755 //var//spool//asterisk//voicemail//brights//" + getOnlyMailBox() + "//INBOX//msg0000.wav");
    As you see the inverted commas end at "brights//", and this indicates that command is finishing here but it's not the case. I want that whole thing is written in single inverted commas so it become full path and the command is executed on the defined path. Like

    Java Code:
    Process myProcess = Runtime.getRuntime().exec("chmod 755 //var//spool//asterisk//voicemail//brights//  getOnlyMailBox()  //INBOX//msg0000.wav");
    But in this case i have no way to get the value because it is treated as a whole string(constant).

    So can any one tell me how can i give path here so the command execute. Whatever value getOnlyMailBox() receive , substitute here and then it becomes a full path and then command execute on this path.


  2. #2
    FON is offline Senior Member
    Join Date
    Dec 2009
    Belgrade, Serbia
    Rep Power


    Let's clear thing a bit.

    Why this cannot be a solution :
    Java Code:
    String dynamicPath =  getOnlyMailBox() ;
    Process myProcess = 
    Runtime.getRuntime().exec("chmod 755 //var//spool//asterisk//voicemail//brights//" + dynamicPath + "//INBOX//msg0000.wav");
    "Whatever value getOnlyMailBox() receive" ???

    If you work with files there has to be some path predefiend.

    I have no idea what getOnlyMailBox() does
    but it has to give you path (or part of it) that already exists
    or you will look for a file on non-existing path.

    As i see it its all about String concatenation and defining good file path ?

Similar Threads

  1. Executing a jar double-click style in Linux
    By goodwillwins in forum AWT / Swing
    Replies: 24
    Last Post: 03-19-2011, 04:56 AM
  2. Executing external command through JSP
    By rudranee in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 03-21-2009, 09:22 AM
  3. Error Occurred Executing Command Line Solution
    By RahulKhire in forum Eclipse
    Replies: 1
    Last Post: 09-10-2008, 01:38 PM
  4. Replies: 0
    Last Post: 06-20-2008, 09:02 AM
  5. Problem during executing Command Prompt
    By keshari in forum Advanced Java
    Replies: 4
    Last Post: 06-05-2008, 04:06 AM

Posting Permissions

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