import java.io.*;
import java.util.*;

public class Project1 {
	// str to put the input from the keyboard
	private static String str = new String();
	public	static BufferedReader in = 
			new BufferedReader(new InputStreamReader(System.in));
	public static void main(String argv[]){
		for (;;) {
			System.out.print("$>");
			System.out.flush();
			try {
				str = in.readLine();
			}
			catch(IOException e){
				System.err.println(e);
			}

			Parser a_parser = new Parser();
			a_parser.parse(str, "&");
			int numberOfCommand = a_parser.getTokens().size();

			// creat threads below
			Thread t[] = new Thread[numberOfCommand];
			for (int i = 0; i < numberOfCommand; i ++){
				String comd = 
					(String)a_parser.getTokens().get(i);
				t[i] = new Thread(new Command(comd));
				t[i].start();
			}
			for (int i = 0;i < numberOfCommand; i ++){
				try {
					t[i].join();
				} catch (InterruptedException e){
					System.err.println(e);
				}
			}
		}//end of for(;;)
	}//end of main();
}// end of class Project1.