我之前使用过这个在Windows系统上启动的东西从未在Mac上尝试过.
public void launchScript(String args)
{
String cmd = null;
try
{
cmd = getParameter(PARAM_CMD);
System.out.println("args value : = " + args);
System.out.println("cmd value : = " + cmd);
System.out.println("Full command: = " + cmd + " " + args);
if (cmd != null && !cmd.trim().equals(""))
{
if (args == null || args.trim().equals(""))
{
final String tempcmd = cmd;
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
try
{
Runtime.getRuntime().exec(tempcmd);
}
catch (Exception e)
{
System.out.println("Caught exception in privileged block, Exception:" + e.toString());
}
return null; // nothing to return
}
});
System.out.println(cmd);
}
else
{
final String tempargs = args;
final String tempcmd1 = cmd;
AccessController.doPrivileged(new PrivilegedAction() {
public Object run()
{
try
{
Runtime.getRuntime().exec(tempcmd1 + " " + tempargs);
}
catch (Exception e)
{
System.out.println("Caught exception in privileged block, Exception:" + e.toString());
}
return null; // nothing to return
}
});
System.out.println(cmd + " " + args);
}
}
else
{
System.out.println("execCmd parameter is null or empty");
}
}
catch (Exception e)
{
System.out.println("Error executing command --> " + cmd + " (" + args + ")");
System.out.println(e);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3539 次 |
| 最近记录: |