zoukankan      html  css  js  c++  java
  • Mac 如果一定要写个锁屏程序的话就这样

    package test;
    
    import java.io.BufferedReader;
    import java.io.File;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    
    public class RuntimeCMD  {
    	
    	private static Process p;
    	
    	public static void main(String[] args) throws IOException, InterruptedException {
    		InputStream in=getInputStreambyExecScript("scripts/test.sh");
    		BufferedReader fr=new BufferedReader(new InputStreamReader(in));
    		String line;
    		while((line=fr.readLine())!=null){
    			System.out.println(line);
    		}
    		p.waitFor();
    		fr.close();
    		p.destroy();
    	}
    	
    	private static InputStream getInputStream(String exec) throws IOException{
    		p=Runtime.getRuntime().exec(exec);
    		return p.getInputStream();
    	}
    	
    	private static InputStream getInputStreambyExecScript(String exec) throws IOException{
    		p=Runtime.getRuntime().exec(new String[]{"/bin/sh","-c",exec},null,null);
    		return p.getInputStream();
    	}
    }
    

     script 

    #!/bin/bash
    '/System/Library/CoreServices/Menu Extras/User.menu/Contents/Resources/CGSession' -suspend
    
    I'm falling off the sky all alone.The courage inside is gonna break the fall. Nothing can dim my light within. I am That I am 程序 = 数据结构 + 算法
  • 相关阅读:
    Java Web-session介绍
    Java异常-一般异常和运行时异常的区别
    Spring控制Hibernate的缓存机制ehcache
    Hibernate-缓存
    Hibernate-入门教程
    Java算法-hash算法
    Java算法-各种题目总结
    Java算法-堆排序
    Java算法-快速排序
    Java算法-归并排序
  • 原文地址:https://www.cnblogs.com/IamThat/p/4359194.html
Copyright © 2011-2022 走看看