簡體   English   中英

在Eclipse / Mac中運行命令(ffprobe)的ProcessBuilder start()方法

[英]ProcessBuilder start() method to run command (ffprobe) in eclipse/mac

我已經在Mac中安裝了ffprobe,目錄是/ usr / local / bin / ffprobe。 當我在終端中運行ffprobe命令時,它工作正常,但當我通過ProcessBuilder在eclipse中運行它時,它無法運行並引發異常, Caused by: java.io.IOException: Cannot run program "ffprobe": error=2, No such file or directory. 但是,當我運行ProcessBuilder給出ffprobe的絕對路徑時,它可以正常工作。

工作代碼:

sample args:[/usr/local/bin/ffprobe, -v, quiet, -print_format, json, -show_format, -show_streams, some_url]

ProcessBuilder pb = new ProcessBuilder(cmdArgs);
Process proc = pb.start();

但是,如果args為[ffprobe, -v, quiet, -print_format, json, -show_format, -show_streams, some_url]

它引發錯誤。 如何在不給出絕對路徑的情況下運行ffprobe命令? 我已經關注了這篇文章,但是無法解決我的問題。

我在Eclipse中的Java進程運行在

Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/

最終,我可以按照Sakra在這篇文章中提到的以下步驟解決此問題:

  1. 在/Applications/Eclipse.app/Contents/MacOS/下創建eclipse.sh
 export ENV_VAR1=/usr/local/bin/ logger "`dirname \\"$0\\"`/eclipse" exec "`dirname \\"$0\\"`/eclipse" $@ 
  1. chmod + x /Applications/Eclipse.app/Contents/MacOS/eclipse.sh

  2. 打開Eclipse.app Info.plist,並將CFBundleExecutable鍵的值從eclipse更改為eclipse.sh。

  3. 強制將LaunchService更新為

    /System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -v -f /Applications/eclipse/Eclipse.app

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM