java Runtime.exec to run shell script

前端 未结 1 1495
梦如初夏
梦如初夏 2020-12-20 01:44

I am using Runtime.getRuntime().exec() to run a shell script from java code. The code works fine when I pass the parameter as string

      Runtime.getRuntime         


        
相关标签:
1条回答
  • 2020-12-20 02:02

    First string became the command. There is no file 'sh test.sh' to be executed.

    Change

     String[] cmd = {"sh test.sh", "/Path/to my/resource file"};
    

    to

    String[] cmd = {"sh",  "test.sh", "/Path/to my/resource file"};
    

    (In general use process builder API)

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