开发者

Is there any remotely cross platform way to execute an external process?

开发者 https://www.devze.com 2023-02-01 00:41 出处:网络
I was looking for advice on how to execute a process that is somewhat cross platform. I have written Java and Ruby implementations of my app, but its less of a language specific problem and more of a

I was looking for advice on how to execute a process that is somewhat cross platform.

I have written Java and Ruby implementations of my app, but its less of a language specific problem and more of a platform specific issue.

E.G on Ubuntu /usr/bin/ is searched for anything I do

# Ruby

`HandBrakeCLI #{args}` # works on Ubuntu and likely other linux distros since HandBrakeCLI is in /usr/bin/

For windows it will search the current directory I am running in. However, If copy the windows executable to the current directory a runtime linking error will cause开发者_运维知识库 it to crash (DLL not present)

The default install path for HandBrakeCLI is in "Program Files(x86)/HandBrake" (x86 only in 64 bit obviously), however Program Files isn't in the search path as far as I can tell.

For MacOSX I have no clue how to execute Mac "Application Folders" from the command line other than with the "open" command. But that is less of an issue since what I am really after is HandBrakeCLI which is just a normal executable. However HandBrakeCLI is not installed to /usr/bin or /usr/local/bin ( or any variation there of )

My best idea is to make a config file that has the path to HandBrakeCLI. If I go that route however it would be ideal to be able to detect what platform I am on, but that is another problem all together. One I have only done with C #ifdef sections and not in Ruby or Java.

I would appreciate any and all input.


You can get the current OS in Java using

System.getProperty("os.name")

In ruby:

require 'rbconfig'
puts Config::CONFIG['host_os'] 

Hope this helps :)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号