亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Java 命令提示符命令拋出“沒有這樣的文件或目錄”

Java 命令提示符命令拋出“沒有這樣的文件或目錄”

暮色呼如 2023-04-13 15:19:25
我目前正在開發一個應該執行一些控制臺命令的程序。我的代碼如下所示:  private String executeCommands(String[] commands)  {    String result = "";    try    {      ProcessBuilder pb = new ProcessBuilder();      String s = null;      Charset charset = Charset.forName("IBM850");      BufferedReader stdInput;      Process proc;      for (String command : commands)      {        System.out.println("Ausfuehrung von: " + command);        pb.command(command);        proc = pb.start();        stdInput = new BufferedReader(new InputStreamReader(proc.getInputStream(), charset));        while ((s = stdInput.readLine()) != null)        {          result += s;        }        System.out.println();      }    }    catch (Exception ex)    {      result = ex.getMessage();    }    return result;  }  private void userLogIn(IUserInteraction userInteraction)  {    String[] command = { "svn auth --show-passwords" };    String result = executeCommands(command);    System.out.println(result);  }輸出是“無法運行程序“svn auth --show-passwords”:錯誤=2,沒有這樣的文件或目錄”,但是當我在控制臺中手動輸入命令時,它起作用了。我做錯了什么?提前致謝!
查看完整描述

2 回答

?
慕尼黑8549860

TA貢獻1818條經驗 獲得超11個贊

經過一些嘗試,我找到了一個可行的解決方案


String result

String line;

      Process process = Runtime.getRuntime().exec(command);

      Reader r = new InputStreamReader(process.getInputStream());

      BufferedReader in = new BufferedReader(r);

      while ((line = in.readLine()) != null)

        result += line;

      in.close();


查看完整回答
反對 回復 2023-04-13
?
喵喔喔

TA貢獻1735條經驗 獲得超5個贊

svn如果您的應用程序未攜帶環境變量,則對 jvm 沒有任何意義。

嘗試使用完整路徑執行命令:

String[] command = { "/bin/dir1/dir2/svn auth --show-passwords" };

如果您不知道程序在哪里,請使用以下命令找出它:

which svn


查看完整回答
反對 回復 2023-04-13
  • 2 回答
  • 0 關注
  • 225 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號