i need to enter commands in one line using delimiter "&" (ampersand) or ";" (semicolon),using one type of delimiter in a line. e.g "cat&cp&rm" or "cat;cp;rm". Both should not be used in one line e.g "cat;cp&rm", when this happens the system exits.
I've tried the code below using Split method but i want to use an IF statement for the above condition. i also want to run a thread for each command if the commands are seperated by "&" and run only one thread for all commands being executed one after another if they're seperated by ";".
import java.lang.*;
import java.io.*;
import java.util.*;
public class Parsing
{
public static void main(String args[]) throws Exception
{
new Parsing().Split();
}
public void Split()
{
String command = " ";
System.out.print("Enter command: " );
try{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
command = br.readLine();
String [] temp = null;
temp = command.split("&");
/*if((temp.equals("&")) || (temp.equals(";")))
{
write(temp);
}
else
{
System.exit(0);
}*/
}catch (IOException e){}
}
public void write(String []s)
{
for (int i = 0 ; i < s.length ; i++)
{
System.out.println(s[i]);
}
}
}
how should i do that? please help me. even if there's no actual solution, i need your suggestions. Thanks in advance