activiti shell 任务

shell 任务用于执行shell 脚本,在Service TAsk 中配置 ,可以用javaf提供的api来执行shell命令
需要使用java.lang.Runtime为原exec()执行shell,也可用java.lang.ProcessBuilder来执行

ProcessBuilder例子:
public class JavaShellTest{
	public static void main(String[] args) throws IOException {
		List list=new ArrayList<>();
		list.add("cmd");
		list.add("/c");
		list.add("echo");
		list.add("hello");
		
		ProcessBuilder builder=new ProcessBuilder(list);
		//执行命令
		Process process = builder.start();
		String result=convertStream(process.getInputStream());
		System.out.println(result);
	}
	
	public static String convertStream(InputStream is) throws IOException{
		if(is!=null) {
			Writer writer=new StringWriter();
			char[] buffer =new char[1024];
			try {
				Reader reader= new BufferedReader(new InputStreamReader(is, "UTF-8"));
				int n;
				while((n=reader.read(buffer))!=-1) {
					writer.write(buffer,0,buffer.length);
				}
			}finally {
				is.close();
			}
			return writer.toString();
		}else {
			return "";
		}
	}



2. 现在在bpmn中添加配置

    
        
        
        
        
        
    



3. 通过runtimeService获取就行了
ProcessDefinition pd=rs.createProcessDefinitionQuery().deployment(deploy.getId()).singleResult();

ProcessInstance pi=runtimeService.startProcessInstanceById(pd.getId());

runtimeService.getVariable(pi.getId(),"javaHome");

 

你可能感兴趣的:(java,activiti)