create a shell using java

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gisto moss
    New Member
    • Oct 2009
    • 1

    create a shell using java

    i have to implement the shell such that it accepts commands, together with parameters. Assume all possible commands have either 0 or 1 parameter. I need to check this.
    if(commandstrin gs.length>2) {output error message and continue to the beginning of the loop}

    Note: the continue statement will skip all the following lines and go back to the beginning of the while loop.
    In the skeleton, commandLine=con sole.readLine() ; reads in a command and assigns it to the commandLine string. If the command has an argument, then the command and the argument will be separated by a space, but in a single string. However, ProcessBuilder cannot use such a string. When executing “new ProcessBuilder( )”, the constructor takes in 1 or more strings as arguments. The first should be the command string, and the second, the argument string, if there is an argument. This means we have to separate the commandLine into its individual components. This could be done as follows:
    commands=comman dLine.split(“ “); i.e. split the commandLine string using a space as a separator.
    The individual component strings are stored in commands, which should be an array of strings. Thus, if the user entered the following command at the jsh> prompt: ls -la, commands*0+ will have “ls” and commands*1+ will have “-la”.
    One can then do pb=new ProcessBuilder( commands[0],commands[1]).
    Then ProcessBuilder’ s directory method can be used to set the working directory, as you did in the lab exercise e.g. pb.directory(ne w File(workingdir ectory));
  • YarrOfDoom
    Recognized Expert Top Contributor
    • Aug 2007
    • 1243

    #2
    Could you please bring some structure into the question? It's quite hard to understand what exactly you are asking when no question is clearly defined.
    It would also be quite helpful if you posted the code you have so far, instead of describing it. If you post code, you can put [code]-tags around it ( [code] in front of it, and [/code] behind it).

    I see it's your first post here, so here's a link to the FAQ & Posting Guidelines, which contain a lot of useful information for getting the best out of this forum.

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #3
      @gisto moss: are you also JavaNut13 on the Sun Java forums? If so: people don't like crossposting.

      kind regards,

      Jos

      Comment

      • JavaNut13
        New Member
        • Jun 2013
        • 1

        #4
        No, he's not.

        I'm the only me there can be.

        Comment

        Working...