我正在尝试运行外部可执行文件,但显然它需要提升.代码是这样的,从使用ProcessBuilder的示例修改(因此具有一个参数的数组):
public static void main(String[] args) throws IOException {
File demo = new File("C:\\xyzwsdemo");
if(!demo.exists()) demo.mkdirs();
String[] command = {"C:\\fakepath\\bsdiff4.3-win32\\bspatch.exe"};
ProcessBuilder pb = new ProcessBuilder( command );
Process process = pb.start();
InputStream is = process.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line;
System.out.printf("Output of running %s is:\n", Arrays.toString(command));
while ((line = br.readLine()) != null) {
System.out.println(line);
}
try {
int exitValue = process.waitFor();
System.out.println("\n\nExit Value is " + exitValue);
} catch (InterruptedException e) {
e.printStackTrace(); …Run Code Online (Sandbox Code Playgroud)