Results 1 to 3 of 3
Thread: Ubuntu process manipulation
- 04-09-2012, 01:02 AM #1
Member
- Join Date
- Nov 2010
- Posts
- 66
- Rep Power
- 0
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:
Please help! :)Java Code:package ubuntuprocess; import java.io.BufferedReader; import java.io.File; import java.io.InputStream; import java.io.InputStreamReader; 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 java.io.IOException { 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(System.in)); // we break out with <control><C> while (true) { // read what they entered System.out.print("jsh>"); commandLine = console.readLine(); // if they entered a return, just loop again if (commandLine.equals("")) continue; // now parse it List<String> input = new ArrayList<String>(); StringTokenizer tokenizer = new StringTokenizer(commandLine); while (tokenizer.hasMoreTokens()) input.add(tokenizer.nextToken()); ProcessBuilder pb = new ProcessBuilder(input); pb.directory(File); // 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) System.out.println(line); br.close(); } catch (java.io.IOException ioe) { System.err.println("Error"); System.err.println(ioe); } finally { if (br != null) br.close(); } } } }
- 04-09-2012, 01:42 AM #2
Re: Ubuntu process manipulation
Can you explain your problem? Asking some specific questions would help.I am having troubleIf you don't understand my response, don't ignore it, ask a question.
- 04-09-2012, 06:22 AM #3
Member
- Join Date
- Nov 2010
- Posts
- 66
- Rep Power
- 0
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
-
File manipulation
By cwbr in forum New To JavaReplies: 1Last Post: 11-25-2011, 11:17 AM -
String Manipulation
By tmotse in forum New To JavaReplies: 1Last Post: 10-14-2010, 01:25 PM -
Image Manipulation
By sh100 in forum New To JavaReplies: 0Last Post: 11-03-2009, 10:18 AM -
Image manipulation.
By ambikark in forum Advanced JavaReplies: 0Last Post: 10-15-2008, 01:37 PM -
Array manipulation
By Ms.Ranjan in forum New To JavaReplies: 9Last Post: 07-18-2008, 09:10 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks