Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * @(#)Command0.java		Created at 2013-7-12
   * 
   * Copyright (c) 2011-2013 azolla.org All rights reserved.
   * Azolla PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. 
   */
  package org.azolla.l.ling.lang;
  
 
 
The coder is very lazy, nothing to write for this Command0 class

Author(s):
sk@azolla.org
Since:
ADK1.0
 
 public final class Command0
 {
 	private static final String	INPUT"INPUT";
 
 	private static final String	ERROR"ERROR";
 
 	public static final String	CMD_PAUSE_FLAG">pause";
 
 	public static final String	SH_PAUSE_FLAG">read -n 1 -p";
 
 	//33 Minutes
 	public static final long	DEFAULT_TIMEOUT_MINUTES	= 33;
 
 	public static boolean exec(String command)
 	{
 		return exec(command);
 	}
 
 	public static boolean exec(String commandlong timeout)
 	{
 		return exec(commandtimeoutfalsenull);
 	}
 
 	public static boolean exec(String commandboolean value4pauseString pauseFlag)
 	{
 		return exec(commandvalue4pausepauseFlag);
 	}

The coder is very lazy, nothing to write for this exec method

Parameters:
command command or bat or shell
timeout timeout
value4pause the value for meet pause
pauseFlag pause flag
Returns:
boolean
 
 	public static boolean exec(String commandlong timeoutboolean value4pauseString pauseFlag)
 	{
 		Log0.info(Command0.classcommand);
 
 		boolean rtnBoolean = true;
 
 		//java.lang.NullPointerException
 		//java.lang.IllegalArgumentException: Empty command
 		if(!Strings.isNullOrEmpty(command))
 		{
 			Process process = null;
 			Future<BooleaniFuture = null;
 			Future<BooleaneFuture = null;
 			try
 			{
 				process = Runtime.getRuntime().exec(command);
 				ExecutorService es = Executors.newFixedThreadPool(2);
 				iFuture = es.submit(new CommandTask(process.getInputStream(), value4pausepauseFlag));
 				eFuture = es.submit(new CommandTask(process.getErrorStream(), value4pausepauseFlag));
 				rtnBoolean = iFuture.get(timeout.) && eFuture.get(timeout.) && process.waitFor() == 0;
 			}
 			catch(Exception e)
 			{
                 Log0.error(Command0.class.., KV.ins("command"command).put("timeout"timeout).put("value4pause"value4pause).put("pauseFlag"pauseFlag), e);
 				rtnBoolean = false;
 			}
 			finally
 			{
 				if(null != iFuture)
 				{
					iFuture.cancel(true);
				}
				if(null != eFuture)
				{
					eFuture.cancel(true);
				}
				if(null != process)
				{
					process.destroy();
				}
			}
		}
		return rtnBoolean;
	}
	private static class CommandTask implements Callable<Boolean>
	{
		private String				type;
		private boolean				value4pause;
		private String				pauseFlag;
		//		public CommandTask(InputStream inputStream, String type)
		//		{
		//			this(inputStream, type, false, null);
		//		}
		public CommandTask(InputStream inputStreamString typeboolean value4pauseString pauseFlag)
		{
			super();
			this. = inputStream;
			this. = type;
			this. = value4pause;
			this. = pauseFlag;
		}
		public Boolean call()
		{
			boolean rtnBoolean = true;
			LineNumberReader lineNumberReader = null;
			InputStreamReader inputStreamReader = null;
			String line = null;
			try
			{
				inputStreamReader = new InputStreamReader();
				lineNumberReader = new LineNumberReader(inputStreamReader);
				{
					while((line = lineNumberReader.readLine()) != null)
					{
						Log0.info(CommandTask.class + . + line);
					}
				}
				else
				{
					while((line = lineNumberReader.readLine()) != null)
					{
                        Log0.info(CommandTask.class + . + line);
						{
							rtnBoolean = ;
							break;
						}
					}
				}
			}
			catch(Exception e)
			{
                Log0.error(CommandTask.class.., KV.ins("type").put("value4pause").put("pauseFlag"), e);
				rtnBoolean = false;
			}
			finally
			{
                Close0.close(lineNumberReader);
                Close0.close(inputStreamReader);
			}
			return rtnBoolean;
		}
	}
New to GrepCode? Check out our FAQ X