C#程序不会从Java执行 [英] C# program wont be executed from Java

查看:161
本文介绍了C#程序不会从Java执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个C#程序,我做,虽然我可以运行它通过点击exe文件或通过点击一个批处理文件,我不能启动程序我运行它的java程序。我试过这行代码,无法让软件运行。

I have this C# program i made and while i can run it fine by clicking the exe file or by clicking on a batch file, I cant start up the program on a java program I made to run it. I have tried this line of code and couldn't get the software to run.

Runtime.getRuntime().exec("nameOfTheExeFile");

或将其设置为启动程序的批处理文件。

or set it to the batch file i made that starts the program.

Runtime.getRuntime().exec("nameOfTheBatchFile");

现在有趣的是,当我尝试使用批处理文件时,我得到一个错误,无法找到,但当我双击批处理文件,它将启动exe文件只是罚款。

Now the interesting thing is when I try it with the batch file i get an error saying that the file cannot be found but when i double click the batch file it will start the exe file just fine.

我甚至尝试使用过程,但我没有得到任何运气该过程也一样

I have even tried to use Process but I am not getting any luck with that process as well

List cmdAndArgs = Arrays.asList(new String[]{"cmd.exe", "/c", "ProgramName.exe"});

ProcessBuilder pb = new ProcessBuilder(cmdAndArgs);

Process p = pb.start();

奇怪的是我根本没有得到任何错误。即使我尝试单元测试,我没有任何错误。有没有一个过程,我失踪或什么?

Strange thing is i dont get any error at all. Even when i try unit testing i don't any error's at all. Is there a process I am missing or something ? I am lost on what to do.

更新:

当我检查任务管理器时,我可以看到程序正在运行,但不是exe版本。我看到ProgramName.vshost.exe,有​​没有理由显示,而不是exe文件?

When i check on the task manager i can see that the program is running but not the exe version. I see ProgramName.vshost.exe , is there a reason for this to be showing and not the exe file ?

推荐答案

由于你的程序是命令行程序,你需要从cmd启动它。我不知道这是否是最好的方法,但它的工作。

Since your program is command line program you need to start it from cmd. I'm not sure if this is the best way to do it, but it works.

Runtime.getRuntime().exec("cmd /c start nameOfTheBatchFile");

批处理文件:

start cmd.exe /k "nameOfExeFile"
exit

这篇关于C#程序不会从Java执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆