📄 connecthost.java.svn-base
字号:
/*
* @(#)ConnectHost.java 2004-8-16
*
* www.2163.com 世纪恒通2003(C)
*/
package com.onet.autobill.changemessage;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
/**
* 运行主机命令
*
* @author
* @version 2.0
*/
public class ConnectHost {
private static Logger log = Logger.getLogger(ConnectHost.class);
/**
* 根据给定的路径读取批处理文件
*
* @param config 给定的字符串
* "net use \\ip password /user:usename"
* @return 成功连接指定机器返回 0, 失败则返回1
* @throws IOException
* @throws InterruptedException
*/
public static int executeCommand(String config) {
int connectFlg = 1;
try{
Process process = null;
Runtime command = Runtime.getRuntime();
process = command.exec(config);
InputStream inPut = process.getInputStream();
BufferedReader in = new BufferedReader(new InputStreamReader(inPut));
StringBuffer outPutString = new StringBuffer();
String outMessage;
while((outMessage = in.readLine()) != null){
outMessage = outMessage + "\r\n";
outPutString.append(outMessage);
}
log.info(outPutString.toString());
connectFlg = process.waitFor();
}catch(Exception e){
log.error("数据入库失败!", e);
}
return connectFlg;
}
public static void main(String[] args) throws InterruptedException {
PropertyConfigurator.configureAndWatch("config/log4j.properties", 5000);
//int errcode = executeCommand("bcp bill.dbo.test in temp/ah8257.20070420.sms.txt -c -t, -S192.168.16.60 -Usa -P");
int errcode = executeCommand("bcp TESTBILL.dbo.Change11_200806_Message in file/11changeMessage.txt -c -S192.168.16.46 -Usa -P111111");
log.info("errcode:" + errcode);
log.info("connected");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -