Running a bash shell script in java

后端 未结 3 1656
滥情空心
滥情空心 2020-12-05 05:32

I want to run a shell script from my program below but it doesn\'t seem to do anything. I\'ve run the same command directly in the linux terminal and it works fine so I\'m g

3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-05 06:21

    Try this, it will work.

    String[] cmd = new String[]{"/bin/sh", "path/to/script.sh"};
    Process pr = Runtime.getRuntime().exec(cmd);
    

提交回复
热议问题