易截截图软件、单文件、免安装、纯绿色、仅160KB

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) {
}


相关文档:

七大步骤建立可靠的Linux操作系统


许多刚接触Linux的网络管理员发现,他们很难由指向点击式的安全配置界面转换到另一种基于编辑复杂而难以捉摸的文本文件的界面。本文列出七条管理员能够也应该可以做到的步骤,从而帮助他们建立更加安全的Linux服务器,并显著降低他们所面临的风险。
请任何大型机构的网络管理员对Linux和网络操作系统(如Windows NT或No ......

linux作业管理(ctrl+z,fg,jobs,kill等)

作业管理
1.将“当前”作业放到后台“暂停”:ctrl+z
2.观察当前后台作业状态:jobs
参数:
-l 除了列出作业号之外同时列出PID  
-r:列出仅在后台运行(run)的作业
-s:仅列出暂停的作业
3.将后台作业拿到前台处理:fg
fg %jobnumber (%可有可无)
4.让作业在后台运行:bg
ctrl ......

Linux开启SSH

#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 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号