Runtime.exec on argument containing multiple spaces

前端 未结 8 853
闹比i
闹比i 2020-11-30 15:15

Can anyone make the following run?

public class ExecTest {
  public static void main(String[] args) {
    try {
      //Notice the multiple spaces in the arg         


        
8条回答
  •  春和景丽
    2020-11-30 15:33

    Use new File(pathName).canExecute() first to check whether it's executable or not

    EDIT:

    public static void runAll(String... cmd)
    {
        for(String s : cmd)
        {
            try
            {
                Runtime.getRuntime().exec(cmd);
            }
            catch(Exception e)
            {
                e.printStackTrace();
            }
        }
    }
    

    and then you can use it like: runAll("explorer.exe", "taskmgr.exe");

提交回复
热议问题