⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 runcommand.java

📁 银行项目为后台socket通信写的程序
💻 JAVA
字号:
/****************************************************************************
 * Package		: com.ecSolutions.ecAppServer.util
 * File			: RunCommand.java
 * Create Date  : 2007-7-21
 * Author		: Steven Chen
 * 
 * Copyright(C) 2006 ecSolutions(shanghai) Co.,Limited.All Rights Reserved.
 *			
 ***************************************************************************/
package com.ecSolutions.ecAppServer.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;

import org.apache.log4j.Logger;

import com.ecSolutions.ecAppServer.appSession.ExecFunctionFailException;

public class RunCommand {
	private static HashSet cobolgntSet = null;
	private static Logger log = Logger.getLogger("RunCommand");
	
	public static Process exec(String sessionID, String userid, String command) throws ExecFunctionFailException {
		if(sessionID==null || sessionID.trim().equals("")){
			log.error("sessionID is NULL or empaty");
			throw new ExecFunctionFailException("ERROR");
		}
		if(userid==null || userid.trim().equals("")){
			log.error("userid is NULL or empaty");
			throw new ExecFunctionFailException("ERROR");
		}
		/*
		if (cobolgntSet == null) {
			//String envPath = System.getProperty("java.library.path");
			cobolgntSet = new HashSet();
			Process p;
			String envPath ="";
			try {
				p = Runtime.getRuntime().exec("env COBPATH");
				BufferedReader br =new BufferedReader(new InputStreamReader(p.getInputStream()));
				envPath = br.readLine();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}  
			
			System.out.print(envPath);
			System.out.println("--------------------------------------");
			String sqlElements[] = envPath.split(":");
			for (int i = 0; i < sqlElements.length; i++) {
				System.out.println("-->" + i + " :    " + sqlElements[i]);
			}
			for (int i = 0; i < sqlElements.length; i++) {
				if (sqlElements[i] != null && sqlElements[i].trim().equals("") == false) {
					File dir = new File(sqlElements[i].trim()); // 用File
					// 对象表示一个目录
					Filter filter = new Filter("gnt"); // 生成一个名为java的过滤器
					System.out.println("list java files in directory " + dir);
					String files[] = dir.list(filter); // 列出目录dir下,文件后缀名为gnt的所有文件
					for (int j = 0; j < files.length; j++) {
						File f = new File(dir, files[j]); // 为目录dir 下的文件或目录
						if (f.isFile()) {// 如果该对象为后缀为gnt的文件,put to set
							String filename = f.getName();
							filename = filename.substring(0,filename.lastIndexOf(".gnt"));
							System.out.println("--:" + filename);
							cobolgntSet.add(filename);
							
						}
					}

				}
			}

		}
		System.out.println("--------------------------1");
		if(cobolgntSet.contains(command)==false){
			log.error("The Request Command to execute is not exist in user path!......");
			throw new ExecFunctionFailException("CMDNOTEXIST");
		}
		System.out.println("--------------------------2");
		*/
		try {
			String[] envp = new String[2];
			//envp[0] = "HOSTNAME=" + hostname;
			//envp[1] = "USERID=" + userid;
			Runtime rt = Runtime.getRuntime();
			log.debug("--------------------------3");
			//String[] cmd ={"/bin/sh", "-c", "TMRUN TAMICRPX" , " " + "t" + commands[0] + " " + commands[1] , " > out" }; 
			//String[] cmd ={"/TAMIC23/T2311/gu/TMRUN", " TAMICRPX t" + commands[0] + " " + commands[1], " > out " };
			//---String[] cmd ={"/bin/sh","-c","TAMICRPX.sh " + command + " " + sessionID + " " +  userid};
			//---log.debug("--------------------------4-----" + cmd[0] + " " + cmd[1] + " " + cmd[2] );
			
			Process proc = rt.exec("C:/EcEx/ecExAdminConsole/ecExAdminConsole.exe");
			return proc ;
			/*
			InputStreamReader isr = new InputStreamReader(proc.getInputStream());
			BufferedReader br = new BufferedReader(isr);
			System.out.println("--------------------------5");
			String line = null;
			System.out.println("=======================================================");
			System.out.println("--------------------------6");
			while ((line = br.readLine()) != null) {
				System.out.println("Output" + ">" + line);
			}
			System.out.println("--------------------------7");
			System.out.println("=======================================================");
			System.out.println("");
			*/
		} catch (Exception e) {
			e.printStackTrace();
			throw new ExecFunctionFailException(e);
		}
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -