473,394 Members | 1,737 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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(commandstrings.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=console.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=commandLine.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(new File(workingdirectory));
Oct 9 '09 #1
3 5090
YarrOfDoom
1,247 Expert 1GB
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.
Oct 9 '09 #2
JosAH
11,448 Expert 8TB
@gisto moss: are you also JavaNut13 on the Sun Java forums? If so: people don't like crossposting.

kind regards,

Jos
Oct 10 '09 #3
No, he's not.

I'm the only me there can be.
Jun 23 '13 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: John Bowling | last post by:
I'm creating a routine (not in a browser) to move multiple files on a daily basis to a backup directory. It can be done easily by call shell functions like 'mv file* newdir'. I can't find any...
3
by: John Bowling | last post by:
I have a java (2.0) program with the following lines: String cmdArray1 = {"lp", "-d", "hp4m", "MyFile"}; System.out.println(Runtime.getRuntime().exec(cmdArray1)); It compliles properly, but...
4
by: Laura P | last post by:
Hi, I wasn't sure whether this should be posted in the Java are or in a Solaris thread, so I shall post it in both. Sorry for the duplication. I am new to Solaris and am having trouble...
3
by: Nico | last post by:
I try to execute a shell command from ASP with: response.write("start") Set wshShell = CreateObject("WScript.Shell") wshShell.Run "notepad" Set wshShell = Nothing response.write("finished") ...
0
by: Kyle | last post by:
To any who chose to provide an answer, or even any suggestions to this problem, I thank you greatly in advance. +200 pts. for any valid solutions. I am currently in the process of converting a...
1
by: iksrazal | last post by:
Hi all, I've been struggling to make this command work from Java: /usr/bin/mysql c4 --user=root --password=mypass -e "source /home/crissilva/c4.sql" Works fine as shown when run from the...
21
by: Tom Gur | last post by:
Hi, It's seems that csh and tcsh acts a bit different when handling special characters in quotes. i.e: if i'll supply my program with the following arguments: -winpath "c:\\temp\\" tcsh will...
3
by: vaskarbasak | last post by:
Hi All, i want to run shell script from java.shell script run successfully and generate a file. But when i want to check the existence of that file,it shows that the file is not present. ...
2
by: smitanaik | last post by:
i have a java file which i am running through shell script. the syntax that i have used is #! /bin/bash javac Copy.java
7
by: Samuel A. Falvo II | last post by:
I have a shell script script.sh that launches a Java process in the background using the &-operator, like so: #!/bin/bash java ... arguments here ... & In my Python code, I want to invoke...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.