无法执行批处理文件

时间:2017-11-22 09:20:33

标签: java batch-file cmd

我有这组java代码:

public class OpenBatchFile {
public OpenBatchFile() {
    super();
}

/**Main Method
 * @param args
 */
public static void main(String[] args) {
    //Get Runtime object
    Runtime runtime = Runtime.getRuntime();
    try {
        //Pass string in this format to open Batch file
        runtime.exec("cmd /c start Desktop:\\OpenNotepad.bat");
    } catch (IOException e) {
        System.out.println(e);
    }
  }
}

当我在cmd上键入start Desktop:\\OpenNotepad.bat命令时,访问被拒绝。我收到一个错误说明:

  

没有与执行请求的操作相关联的程序。请安装程序,或者如果已经安装了程序,则在“默认程序”控制面板中创建一个关联。

我必须在代码中添加什么来执行OpenNotepad.bat文件?有人请帮帮我。非常感谢你。

2 个答案:

答案 0 :(得分:2)

clause = ''' function() { var value2 = +this.key2; var value3 = +this.key3; var result = Math.sin(value2) * Math.cos(value3) * Math.sin(value2-value3); return result <= 0.1; } ''' collection = query.where(clause) 中,没有像cmd那样的内容。你可能想要:

Desktop:\\OpenNotepad.bat

给定,start "" "%desktop%\OpenNotepad.bat" 已定义。如果没有,请使用

%desktop%

或只是

start "" "%homepath%\desktop\OpenNotepad.bat"

"%desktop%\OpenNotepad.bat"

答案 1 :(得分:1)

尝试使用

%UserProfile%\Desktop\