QQ主窗体屏幕边缘自动隐藏设置
2011-11-21 15:29
579 查看
方法一
//Process p = Runtime.getRuntime().exec("ping 127.0.0.1 -t");
Process p = Runtime.getRuntime().exec("javac");
InputStream is = p.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
String line;
while((line = reader.readLine())!= null){
System.out.println(line);
}
p.waitFor();
is.close();
reader.close();
p.destroy();
}
方法二
package com.cmd;
import java.lang.*;
import java.io.*;
public class Process {
public static void main(String[] args) {
java.lang.Process process = null;
try {
process = Runtime.getRuntime().exec("net user");
ByteArrayOutputStream resultOutStream = new ByteArrayOutputStream();
InputStream errorInStream = new BufferedInputStream(process.getErrorStream());
InputStream processInStream = new BufferedInputStream(process.getInputStream());
int num = 0;
byte[] bs = new byte[1024];
while((num=errorInStream.read(bs))!=-1){
resultOutStream.write(bs,0,num);
}
while((num=processInStream.read(bs))!=-1){
resultOutStream.write(bs,0,num);
}
String result=new String(resultOutStream.toByteArray());
System.out.println(result);
errorInStream.close(); errorInStream=null;
processInStream.close(); processInStream=null;
resultOutStream.close(); resultOutStream=null;
} catch (IOException e) {
e.printStackTrace();
}finally{
if(process!=null) process.destroy();
process=null;
}
}
}
4. Runtime.exec() 不等同于直接执行command line命令!
啊,我算是在这里吃了苦头了。Runtime.exec()很有局限性,对有些命令不能直接把command line里的内容当作String参数传给exec().
比如重定向等命令。举个例子:
javap -l xxx > output.txt
这时要用到exec的第二种重载,即input 参数为String[]:
Process p = Runtime.getRuntime().exec(new String[]{"/bin/sh","-c","javap -l xxx > output.txt"});
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.util.ArrayList;
import java.util.List;
public class test{
/**
* 运行shell脚本
* @param shell 需要运行的shell脚本
*/
public static void execShell(String shell){
try {
Runtime rt = Runtime.getRuntime();
rt.exec(shell);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 运行shell
*
* @param shStr
* 需要执行的shell
* @return
* @throws IOException
*/
public static List runShell(String shStr) throws Exception {
List<String> strList = new ArrayList();
Process process;
process = Runtime.getRuntime().exec(new String[]{"/bin/sh","-c",shStr},null,null);
//process = Runtime.getRuntime().exec(shStr);
InputStreamReader ir = new InputStreamReader(process
.getInputStream());
LineNumberReader input = new LineNumberReader(ir);
String line;
process.waitFor();
while ((line = input.readLine()) != null){
System.out.println(line);
strList.add(line);
}
return strList;
}
public static void main(String []arge)throws Exception {
test t=new test();
t.runShell("/home/ubuntu/soft/tomcat/bin/startup.sh")
}
String[] cmd = new String[]{"/bin/sh","-c", " ps -ef"};
Process ps = Runtime.getRuntime().exec(cmd);
BufferedReader br = new BufferedReader(new InputStreamReader(ps.getInputStream()));
StringBuffer sb = new StringBuffer();
String line;
while ((line = br.readLine()) != null) {
sb.append(line).append("\n");
}
String result = sb.toString();
System.out.println(result);
//Process p = Runtime.getRuntime().exec("ping 127.0.0.1 -t");
Process p = Runtime.getRuntime().exec("javac");
InputStream is = p.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
String line;
while((line = reader.readLine())!= null){
System.out.println(line);
}
p.waitFor();
is.close();
reader.close();
p.destroy();
}
方法二
package com.cmd;
import java.lang.*;
import java.io.*;
public class Process {
public static void main(String[] args) {
java.lang.Process process = null;
try {
process = Runtime.getRuntime().exec("net user");
ByteArrayOutputStream resultOutStream = new ByteArrayOutputStream();
InputStream errorInStream = new BufferedInputStream(process.getErrorStream());
InputStream processInStream = new BufferedInputStream(process.getInputStream());
int num = 0;
byte[] bs = new byte[1024];
while((num=errorInStream.read(bs))!=-1){
resultOutStream.write(bs,0,num);
}
while((num=processInStream.read(bs))!=-1){
resultOutStream.write(bs,0,num);
}
String result=new String(resultOutStream.toByteArray());
System.out.println(result);
errorInStream.close(); errorInStream=null;
processInStream.close(); processInStream=null;
resultOutStream.close(); resultOutStream=null;
} catch (IOException e) {
e.printStackTrace();
}finally{
if(process!=null) process.destroy();
process=null;
}
}
}
4. Runtime.exec() 不等同于直接执行command line命令!
啊,我算是在这里吃了苦头了。Runtime.exec()很有局限性,对有些命令不能直接把command line里的内容当作String参数传给exec().
比如重定向等命令。举个例子:
javap -l xxx > output.txt
这时要用到exec的第二种重载,即input 参数为String[]:
Process p = Runtime.getRuntime().exec(new String[]{"/bin/sh","-c","javap -l xxx > output.txt"});
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.util.ArrayList;
import java.util.List;
public class test{
/**
* 运行shell脚本
* @param shell 需要运行的shell脚本
*/
public static void execShell(String shell){
try {
Runtime rt = Runtime.getRuntime();
rt.exec(shell);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 运行shell
*
* @param shStr
* 需要执行的shell
* @return
* @throws IOException
*/
public static List runShell(String shStr) throws Exception {
List<String> strList = new ArrayList();
Process process;
process = Runtime.getRuntime().exec(new String[]{"/bin/sh","-c",shStr},null,null);
//process = Runtime.getRuntime().exec(shStr);
InputStreamReader ir = new InputStreamReader(process
.getInputStream());
LineNumberReader input = new LineNumberReader(ir);
String line;
process.waitFor();
while ((line = input.readLine()) != null){
System.out.println(line);
strList.add(line);
}
return strList;
}
public static void main(String []arge)throws Exception {
test t=new test();
t.runShell("/home/ubuntu/soft/tomcat/bin/startup.sh")
}
String[] cmd = new String[]{"/bin/sh","-c", " ps -ef"};
Process ps = Runtime.getRuntime().exec(cmd);
BufferedReader br = new BufferedReader(new InputStreamReader(ps.getInputStream()));
StringBuffer sb = new StringBuffer();
String line;
while ((line = br.readLine()) != null) {
sb.append(line).append("\n");
}
String result = sb.toString();
System.out.println(result);
相关文章推荐
- C# 窗体靠近屏幕边缘自动隐藏*学习(类似于QQ)
- 窗体靠近屏幕边缘自动隐藏*学习(类似于QQ)
- C# 窗体靠近屏幕边缘自动隐藏*学习(类似于QQ)
- C# 窗体靠近屏幕边缘自动隐藏*学习(类似于QQ)
- C# 窗体靠近屏幕边缘自动隐藏*学习(类似于QQ)
- [仿QQ聊天工具系列一]关于停靠屏幕边缘时自动隐藏窗体的研究
- Winform窗体实现类似停靠在屏幕边缘时自动隐藏的功能
- Winform窗体实现类似停靠在屏幕边缘时自动隐藏的功能
- C# winform 实现 qq 在屏幕边缘 自动隐藏 鼠标移过去 移上去 又自动显示
- QQ在屏幕边缘自动隐藏不能正常显示
- c# 实现窗体拖到屏幕边缘自动隐藏
- WinForm,窗体靠近屏幕边缘自动隐藏
- Swing中窗体移到屏幕边缘自动隐藏
- Swing中窗体移到屏幕边缘自动隐藏
- Winform窗体实现类似停靠在屏幕边缘时自动隐藏的功能 .doc
- c# 实现窗体拖到屏幕边缘自动隐藏
- C#实现窗体靠近屏幕边界自动隐藏
- C# 屏幕监控 自动截屏程序 主窗体隐藏,仅在进程中显示
- Delphi下QQ窗体自动隐藏探索--1(转帖)