run shell command from java

后端 未结 2 908
孤街浪徒
孤街浪徒 2020-11-28 15:23

I am working on an application an have an issue about running shell command from java application. here is the code:

public String execRuntime(String cmd) {
         


        
相关标签:
2条回答
  • 2020-11-28 15:46

    I recall that the an overload of exec method provides a parameter for the arguments seperately. You need to use that

    Yup. Here is it

    public Process exec(String[] cmdarray)
                 throws IOException
    

    Just make the command line and all arguments Seperate elements of the String array

    0 讨论(0)
  • 2020-11-28 16:10

    first make a string
    String cmd="/export/home/test/myapp -T \"some argument\"";
    then run cmd in proc

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