【问题标题】:Is there a way to specify the home folder while opening the terminal with Java?有没有办法在用 Java 打开终端时指定主文件夹?
【发布时间】:2016-03-05 03:58:12
【问题描述】:

使用以下代码在 Mac 上打开终端非常简单:

Runtime runtime = Runtime.getRuntime();
String[] cmd = {"/Applications/iTerm.app/Contents/MacOS/iTerm"}
runtime.exec(cmd);

BobZhao@mac:~ > pwd
/Users/BobZ

我的默认主文件夹是 /Users/BobZ,有没有办法在打开终端时指定一个路径?

【问题讨论】:

    标签: java linux macos shell


    【解决方案1】:

    有一个exec方法接受三个参数,第三个是你想要的工作目录:

    public Process exec(String command,String[] envp,File dir)
    

    【讨论】:

      猜你喜欢
      • 2021-08-20
      • 2019-01-17
      • 2023-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-30
      • 1970-01-01
      相关资源
      最近更新 更多