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

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。