package LP.SDK;

import java.io.File;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactoryConfigurationError;

public class Program {

	public static void main(String[] args) throws IOException, TransformerConfigurationException, ParserConfigurationException, TransformerException, TransformerFactoryConfigurationError {
		 
				 //浏览器sdk需要放到项目目录下的tools 目录中
			     String currentDir=System.getProperty("user.dir");
				 TaskConfig conf = new TaskConfig();
				 conf.TaskFile=currentDir+ "\\tools\\Projects\\testcmd.lp";
				 MD5 getMD5 = new MD5();
				 DateFormat format = new SimpleDateFormat("yyyyMMdd");
				 conf.SKey="trial:从火车采集器官方获取的试用机器码";
				 conf.LogFilePath=currentDir+"\\tools\\log.txt";
				 conf.ResultFile=currentDir+"\\tools\\result.xml";
				 conf.TaskName="演示火车浏览器SDK的使用";
				 conf.Varlist.put("关键词", "测试");
				 conf.Varlist.put("变量名", "变量值");
				 File logFile=new File(conf.LogFilePath);
				 if( logFile.exists())
				 {
					 logFile.delete();
				 }
				 File resultFile=new File(conf.ResultFile);
				 if(resultFile.exists()){
					 resultFile.delete();
				 }
				 ProcessBuilder pb = new ProcessBuilder(currentDir+"\\tools\\TasksRunner.exe", conf.ToArgString());
			        pb.redirectErrorStream(true);
			        
			        Process ps = pb.start();
			        Scanner scanner = new Scanner(ps.getInputStream());
			        StringBuilder result = new StringBuilder();
			        while (scanner.hasNextLine()) {
			            result.append(scanner.nextLine());
			            result.append(System.getProperty("line.separator"));
			        }
			        scanner.close();
	}

}
