Java调用Linux命令行若干实例
Executing a CommandSee also e90 Reading Output from a Command.
try {
// Execute a command without arguments
String command = "ls";
Process child = Runtime.getRuntime().exec(command);
// Execute a command with an argument
command = "ls /tmp";
child = Runtime.getRuntime().exec(command);
} catch (IOException e) {
}
If an argument contain spaces, it is necessary to use the overload that requires the command and its arguments to be supplied in an array:
try {
// Execute a command with an argument that contains a space
String[] commands = new String[]{"grep", "hello world", "/tmp/f.txt"};
commands = new String[]{"grep", "hello world", "c:\\Documents and Settings\\f.txt"};
Process child = Runtime.getRuntime().exec(commands);
} catch (IOException e) {
}
e90. Reading Output from a Commandtry {
// Execute command
String command = "ls";
Process child = Runtime.getRuntime().exec(command);
// Get the input stream and read from it
InputStream in = child.getInputStream();
int c;
while ((c = in.read()) != -1) {
process((char)c);
}
in.close();
} catch (IOException e) {
}
e91. Sending Input to a Commandtry {
// Execute command
String command = "cat";
Process child = Runtime.getRuntime().exec(command);
// Get output stream to write from it
OutputStream out = child.getOutputStream();
out.write("some text".getBytes());
out.close();
} catch (IOException e) {
}
相关文档:
今天遇到要导出数据库中表的数据。下面这个就可以搞定。。
#导出指定的表 #导出命令 -u用户名 -p密码 -h主机IP地址 数据库名 表名1 表名2 > 导出文件.sql
mysqldump -uroot -proot -h192.168.0.88 ok_db oktable1 oktable2 > ok_db.sql
另外在更改mysql密码时候,网上有些命令不对:
我用如下:set password=pas ......
今天安装了db2,忙了好一阵子,上网找资料等,终于装好了,下面就把我的步骤跟大家分享一下。
第一步:检查程序包及其版本
compat-libstdc++-7.3-2.96.118.i386.rpm
在linux的安装盘上,找到后使用rpm -i compat-libstdc++-7.3-2.96.118.i386.rpm 安装即可
第 ......
三、VMA和PAGE结构 和mmap函数
1.page 主要成员
atomic_t count;
//这个页的引用数. 当这个 count 掉到 0, 这页被返回给空闲列表.
void *virtual;
//如果页被映射,则表示这页的内核虚拟地址; 否则, NULL.
unsigned long flags;
//描述页状态的一套位标志. 这些包括 ......