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) {
}
相关文档:
今天安装了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;
//描述页状态的一套位标志. 这些包括 ......
磁盘与目录的容量
在文字接口底下查看目前的磁盘最大容许容量、已经使用掉的容量、 目前所在目录的已使
用容量
指令 df [-ahikHTm] [目录或文件名]
-a :列出所有的文件系统,包括系统特有的 /proc 等文件系统;
-k :以 KBytes 的容量显示各文件系统;
-m :以 MBytes 的容量显示各文件系统;
......
#pacman -S openssh #安装openssh
安装完成后在/etc/rc.conf的最底部DAEMONS后添加sshd让系统启动时自动启动openssh
DAEMONS=(syslog-ng network netfs crond sshd)
也可手动启动openssl,执行
#/etc/inin.d/sshd start
默认情况下其它电脑是不能通过ssh来访问archlinux的,需要修改两个文件来实现:
/etc/h ......
安装OpenSSH
Ubuntu缺省没有安装SSH Server,使用以下命令安装:
sudo apt-get install openssh-server openssh-client
不过Ubuntu缺省已经安装了ssh client。
配置完成后重起:
sudo /etc/init.d/ssh restart
windows 客户端用putty连接命令shell模式 ......