java中运行c语言的exe文件

java中运行c语言的exe文件,第1张

在java按钮的触发事件唯逗大 方法中写上:Runtime.getRuntime().exec("D:\\Program Files\\vmware.exe")

就可以运行路径指衫为D:\\Program Files\\vmware.exe的外部指竖程序了

import java.io.*

import java.lang.*

import java.nio.charset.*

public class Rt

{

public static void main(String[] args) throws Exception

{

if( args.length == 0 ) {

System.out.println("用法竖唤: java Rt <目标EXE><提供给EXE的参数尺或...>")

return

}

Runtime rt = Runtime.getRuntime()

ProcessBuilder pb = new ProcessBuilder(args)

Process p = pb.start()

p.waitFor()

int exitCode = p.exitValue()

System.out.println("exitCode = " + exitCode)

InputStream resultStream = p.getInputStream()

ByteArrayOutputStream outputStream = new ByteArrayOutputStream()

int size, SIZE = 4096

byte[] buffer = new byte[SIZE]

while( (size = resultStream.read(buffer)) != -1 ) {

outputStream.write(buffer, 0, size)

}

byte[] bytes = outputStream.toByteArray()

outputStream.close()

String str = new String(bytes)

System.out.println(str)

}

/*

#include <stdio.h>

int main(int argc, char *argv[])

{

int i = 0

printf("argc = %d\陵纤伍n", argc)

for(i = 0i <argci ++)

printf("argv[%d] = %s\n", i, argv[i])

return 0

}

*/

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/8238770.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-14
下一篇 2023-04-14

发表评论

登录后才能评论

评论列表(0条)

保存