从 Java 调用预处理器工具
我有一个使用 MCPP(预处理器)进行预处理的 C 源代码。我想用 Java 解析器解析这个预处理过的源代码。为此,我需要从 Java 调用它。是否有一些 API 可以用来处理此类调用。我计划将 DOS 命令作为批处理文件执行,并在 Java 运行时执行。 当我使用标准 exec 方法时,
Runtime r = Runtime.getRuntime();
Process dos = r.exec("cmd.exe /c C:\\mcpp\\bin\\mcpp.exe -Iinclude csample.c");
它给出了预处理器无法打开输入文件的错误。
等待建议。
cmd参数已编辑
I have a C source that I have preprocessed using MCPP, a preprocessor. I want to parse this preprocessed source with Java parser. For that I need to call it from Java. Is there some API available to handle such call. I plan to execute DOS commands as a batch file and execute it at Java Runtime.
When I used the standard exec method
Runtime r = Runtime.getRuntime();
Process dos = r.exec("cmd.exe /c C:\\mcpp\\bin\\mcpp.exe -Iinclude csample.c");
It gives error that preprocessor cannot open input file.
Suggestions awaited.
cmd parameters edited
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我想到 ProcessBuilder
ProcessBuilder comes to my mind
又怎样呢
?
What about
?
您的问题是您的命令正在与您预期不同的目录中运行。您需要使用三参数版本的
exec()
:其中第三个参数给出正在执行的命令的当前目录。确保将其设置为输入所在的目录。
编辑:示例:
Your problem is that your command is being run in a different directory than you expect. You need to provide the appropriate directory using the three-argument version of
exec()
:where the third argument gives the current directory for the command being executed. Make sure to set it to the directory where the input is located.
EDIT: Example: