Running Shell or System Command in JAVA

前端 未结 3 1012
执笔经年
执笔经年 2021-01-16 16:27
private void myFunction(String userName){
    String fileName = this.generateFile(userName);
    String[] command = new String[4];
    command[0] = \"cmd\";
    comm         


        
相关标签:
3条回答
  • 2021-01-16 17:12

    Your command is not in any of the directories in the PATH variable. And it is likely not in the "current working directory" of your Java programms process. Either set PATH correctly, or give the full absolute path to the command which you want to run.

    0 讨论(0)
  • 2021-01-16 17:16

    Try this:

    final Runtime rt = Runtime.getRuntime();
    rt.exec(your command line here as a single String);
    
    0 讨论(0)
  • 2021-01-16 17:19

    At the risk of repeating myself I'm gonna say it again: java.lang.ProcessBuilder is much better option

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