Executing shell-script with parameters from java

前端 未结 3 850
一生所求
一生所求 2021-02-14 07:48

I have been googling for some time, and everyone seems to have a different solution, none of which appear to be working for me.

I have tried both ProcessBuilder

3条回答
  •  情书的邮戳
    2021-02-14 08:09

    In general, I would recommend that you use the ScriptEngine instead of System.getRuntime().exec
    I think it will make things more easy for you.
    Bare in mind you need for this JDK 6 and above.
    In addition, regarding your specific problem - I really think that this issue should be configurable.
    You can do the following:
    A. Have in your .bash_rc or .bash_profile (for each user) define a path to the configuration
    script using:
    EXPORT MY_SCRIPT=


    B. Read this value from java code, using
    String sciprtPath = System.getenv("MY_SCRIPT") to get the value.
    C. Run the script , the way you did in your code, with scriptPath variable, or using the scriptEngine.

提交回复
热议问题