Results 1 to 3 of 3
  1. #1
    Asvin is offline Member
    Join Date
    Nov 2010
    Rep Power

    Default Ubuntu process manipulation

    Hi, I have an assignment that requires a program to do the following things:

    1) Create a process and a basic shell script like the one in the terminal in Ubuntu.
    2) Show the current directory of the process.
    3) Go to and display the home directory, upon entering the command
    4) Change to a certain directory, based on user's command
    5) Create a history feature that stores all the commands like "ls whatever", "ls anotherwhatever", etc.

    I have put together a program that has set up a basic shell called "jsh" and shows the current directory. I am having trouble with the rest of the program! Here is the code:

    Java Code:
    package ubuntuprocess;
    import java.util.ArrayList;
    import java.util.List;
    import java.util.StringTokenizer;
    public class UbuntuProcess
        private static File File;
        public static void main(String[] args) throws {
            String workingDirectory = System.getProperty("user.dir") + "/";
            String homeDirectory = System.getProperty("user.home") + "/";
            String fileSeparator = System.getProperty("file.separator");
            String newDirectory;
            String commandLine;
            File wd;
            BufferedReader console = new BufferedReader(new InputStreamReader(;
            // we break out with <control><C>
            while (true) {
                // read what they entered
                commandLine = console.readLine();
                // if they entered a return, just loop again
                if (commandLine.equals(""))
                // now parse it
                List<String> input = new ArrayList<String>();
                StringTokenizer tokenizer = new StringTokenizer(commandLine);
                while (tokenizer.hasMoreTokens())
                ProcessBuilder pb = new ProcessBuilder(input);
                // now start the process
                BufferedReader br = null;
                try {
                               Process proc = pb.start();
                            // obtain the input and output streams
                            InputStream is = proc.getInputStream();
                            InputStreamReader isr = new InputStreamReader(is);
                            br = new BufferedReader(isr);
                    // read what the process returned
                            String line;
                            while ( (line = br.readLine()) != null)
                } catch ( ioe) {
                finally {
                    if (br != null)
    Please help! :)

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Eastern Florida
    Rep Power

    Default Re: Ubuntu process manipulation

    I am having trouble
    Can you explain your problem? Asking some specific questions would help.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Asvin is offline Member
    Join Date
    Nov 2010
    Rep Power

    Default Re: Ubuntu process manipulation

    Oh, sorry for not being clear.. I want to add a history feature so that when the java program runs and the user types in the command for ubuntu in the terminal like "ls something", the program will show the history of all commands entered.. same goes with the commands to go to the home directory and change the directory to whatever the user types in!

Similar Threads

  1. File manipulation
    By cwbr in forum New To Java
    Replies: 1
    Last Post: 11-25-2011, 12:17 PM
  2. String Manipulation
    By tmotse in forum New To Java
    Replies: 1
    Last Post: 10-14-2010, 02:25 PM
  3. Image Manipulation
    By sh100 in forum New To Java
    Replies: 0
    Last Post: 11-03-2009, 11:18 AM
  4. Image manipulation.
    By ambikark in forum Advanced Java
    Replies: 0
    Last Post: 10-15-2008, 02:37 PM
  5. Array manipulation
    By Ms.Ranjan in forum New To Java
    Replies: 9
    Last Post: 07-18-2008, 10:10 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