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

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

Java 運行時二進制顯示不同的結果

Java 運行時二進制顯示不同的結果

慕無忌1623718 2022-05-21 16:38:21
我正在嘗試使用我的 Java 代碼運行二進制文件,但它給我的結果與我自己從終端運行它時不同。Java代碼:Runtime rt = Runtime.getRuntime();String path = System.getProperty("user.dir") + "/src/main/go/Sentiment";String command = path + " " + "\"i love this\"";System.out.println(command);Process p = rt.exec(command);Scanner s = new Scanner(p.getInputStream()).useDelimiter("\\A");String output = s.hasNext() ? s.next() : "";System.out.println(output);這打?。?home/ninesalt/repositories/elasticsearch-ingest-opennlp/src/main/go/Sentiment “我喜歡這個”0但是,當我在終端中運行相同的命令時,我會得到 1 。為什么會這樣?
查看完整描述

1 回答

?
莫回無

TA貢獻1865條經驗 獲得超7個贊

切換以Runtime.exec(String[])避免引用參數時出現問題:


String command = System.getProperty("user.dir") + "/src/main/go/Sentiment";

String arg = "i love this";


Process p = rt.exec(new String[] { command, arg });


查看完整回答
反對 回復 2022-05-21
  • 1 回答
  • 0 關注
  • 146 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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