execute an external command in java

前端 未结 2 714
天涯浪人
天涯浪人 2020-12-20 02:48

Is there a way to execute a command in java that doesn\'t suffer from the startup overhead (slowness) of using ProcessBuilder?

More detail: I am using im4java which

相关标签:
2条回答
  • 2020-12-20 03:03

    This is not recommended, but you could write a JNI library to do the same thing that ProcessBuilder is doing. Perhaps yours would be faster, but I wouldn't count on it, plus you would lose cross-platform compatibility.

    How slow are we talking here? I'm using ProcessBuilder myself for running Git commands (haven't had a chance to look into JGit yet), and it seems snappy enough. You may have better luck on Linux, as the overhead may actually be in Windows heavyweight process creation.

    0 讨论(0)
  • 2020-12-20 03:07
    Runtime.getRuntime().exec(...)  
    

    can be used to run an external command. You can turn your List into a command array or a string to pass to exec().

    0 讨论(0)
提交回复
热议问题